mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-15 10:30:58 +02:00
Added perf tests
This commit is contained in:
12
README.md
12
README.md
@@ -23,6 +23,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
|||||||
- [How to use Middleware](#how-to-use-middleware)
|
- [How to use Middleware](#how-to-use-middleware)
|
||||||
- [How to use authentication with AuthenticationMiddleware](#how-to-use-authentication-with-authenticationmiddleware)
|
- [How to use authentication with AuthenticationMiddleware](#how-to-use-authentication-with-authenticationmiddleware)
|
||||||
- [Migration to Middleware to improve performance and memory usage](#migration-to-middleware-to-improve-performance-and-memory-usage)
|
- [Migration to Middleware to improve performance and memory usage](#migration-to-middleware-to-improve-performance-and-memory-usage)
|
||||||
|
- [Performance](#performance)
|
||||||
- [Original Documentation](#original-documentation)
|
- [Original Documentation](#original-documentation)
|
||||||
|
|
||||||
## Coordinate and dependencies
|
## Coordinate and dependencies
|
||||||
@@ -221,6 +222,17 @@ myHandler.addMiddleware(&authMiddleware); // add authentication to a specific ha
|
|||||||
These callbacks can be called multiple times during request parsing, so this is up to the user to now call the `AuthenticationMiddleware.allowed(request)` if needed and ideally when the method is called for the first time.
|
These callbacks can be called multiple times during request parsing, so this is up to the user to now call the `AuthenticationMiddleware.allowed(request)` if needed and ideally when the method is called for the first time.
|
||||||
These callbacks are also not triggering the whole middleware chain since they are not part of the request processing workflow (they are not the final handler).
|
These callbacks are also not triggering the whole middleware chain since they are not part of the request processing workflow (they are not the final handler).
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
With the `perf-test` PIO environment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> brew install autocannon
|
||||||
|
> autocannon -c 10 -w 10 -d 20 http://192.168.4.1
|
||||||
|
```
|
||||||
|
|
||||||
|
[](https://mathieu.carbou.me/ESPAsyncWebServer/perf-c10.png)
|
||||||
|
|
||||||
## Original Documentation
|
## Original Documentation
|
||||||
|
|
||||||
- [Why should you care](#why-should-you-care)
|
- [Why should you care](#why-should-you-care)
|
||||||
|
@@ -23,6 +23,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
|||||||
- [How to use Middleware](#how-to-use-middleware)
|
- [How to use Middleware](#how-to-use-middleware)
|
||||||
- [How to use authentication with AuthenticationMiddleware](#how-to-use-authentication-with-authenticationmiddleware)
|
- [How to use authentication with AuthenticationMiddleware](#how-to-use-authentication-with-authenticationmiddleware)
|
||||||
- [Migration to Middleware to improve performance and memory usage](#migration-to-middleware-to-improve-performance-and-memory-usage)
|
- [Migration to Middleware to improve performance and memory usage](#migration-to-middleware-to-improve-performance-and-memory-usage)
|
||||||
|
- [Performance](#performance)
|
||||||
- [Original Documentation](#original-documentation)
|
- [Original Documentation](#original-documentation)
|
||||||
|
|
||||||
## Coordinate and dependencies
|
## Coordinate and dependencies
|
||||||
@@ -221,6 +222,17 @@ myHandler.addMiddleware(&authMiddleware); // add authentication to a specific ha
|
|||||||
These callbacks can be called multiple times during request parsing, so this is up to the user to now call the `AuthenticationMiddleware.allowed(request)` if needed and ideally when the method is called for the first time.
|
These callbacks can be called multiple times during request parsing, so this is up to the user to now call the `AuthenticationMiddleware.allowed(request)` if needed and ideally when the method is called for the first time.
|
||||||
These callbacks are also not triggering the whole middleware chain since they are not part of the request processing workflow (they are not the final handler).
|
These callbacks are also not triggering the whole middleware chain since they are not part of the request processing workflow (they are not the final handler).
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
With the `perf-test` PIO environment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
> brew install autocannon
|
||||||
|
> autocannon -c 10 -w 10 -d 20 http://192.168.4.1
|
||||||
|
```
|
||||||
|
|
||||||
|
[](https://mathieu.carbou.me/ESPAsyncWebServer/perf-c10.png)
|
||||||
|
|
||||||
## Original Documentation
|
## Original Documentation
|
||||||
|
|
||||||
- [Why should you care](#why-should-you-care)
|
- [Why should you care](#why-should-you-care)
|
||||||
|
BIN
docs/perf-c10.png
Normal file
BIN
docs/perf-c10.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 295 KiB |
@@ -27,6 +27,66 @@
|
|||||||
|
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
const char* htmlContent = R"(
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Sample HTML</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello, World!</h1>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
|
||||||
|
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
|
||||||
|
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
|
||||||
|
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
|
||||||
|
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
|
||||||
|
dapibus elit, id varius sem dui id lacus.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)";
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
AsyncEventSource events("/events");
|
AsyncEventSource events("/events");
|
||||||
AsyncWebSocket ws("/ws");
|
AsyncWebSocket ws("/ws");
|
||||||
@@ -236,16 +296,18 @@ void setup() {
|
|||||||
headerFree.keep("X-Keep-Me");
|
headerFree.keep("X-Keep-Me");
|
||||||
headerFree.keep("host");
|
headerFree.keep("host");
|
||||||
|
|
||||||
// global middleware
|
|
||||||
server.addMiddleware(&requestLogger);
|
|
||||||
// server.addMiddlewares({&rateLimit, &cors, &headerFilter});
|
|
||||||
|
|
||||||
cors.setOrigin("http://192.168.4.1");
|
cors.setOrigin("http://192.168.4.1");
|
||||||
cors.setMethods("POST, GET, OPTIONS, DELETE");
|
cors.setMethods("POST, GET, OPTIONS, DELETE");
|
||||||
cors.setHeaders("X-Custom-Header");
|
cors.setHeaders("X-Custom-Header");
|
||||||
cors.setAllowCredentials(false);
|
cors.setAllowCredentials(false);
|
||||||
cors.setMaxAge(600);
|
cors.setMaxAge(600);
|
||||||
|
|
||||||
|
#ifndef PERF_TEST
|
||||||
|
// global middleware
|
||||||
|
server.addMiddleware(&requestLogger);
|
||||||
|
server.addMiddlewares({&rateLimit, &cors, &headerFilter});
|
||||||
|
#endif
|
||||||
|
|
||||||
// Test CORS preflight request
|
// Test CORS preflight request
|
||||||
// curl -v -X OPTIONS -H "origin: http://192.168.4.1" http://192.168.4.1/middleware/cors
|
// curl -v -X OPTIONS -H "origin: http://192.168.4.1" http://192.168.4.1/middleware/cors
|
||||||
server.on("/middleware/cors", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/middleware/cors", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
@@ -320,8 +382,11 @@ void setup() {
|
|||||||
request->redirect("/");
|
request->redirect("/");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// PERF TEST:
|
||||||
|
// > brew install autocannon
|
||||||
|
// > autocannon -c 10 -w 10 -d 20 http://192.168.4.1
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
request->send(200, "text/plain", "Hello, world");
|
request->send(200, "text/html", htmlContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/file", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/file", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
@@ -50,6 +50,11 @@ platform = https://github.com/pioarduino/platform-espressif32/releases/download/
|
|||||||
; board = esp32-s3-devkitc-1
|
; board = esp32-s3-devkitc-1
|
||||||
; board = esp32-c6-devkitc-1
|
; board = esp32-c6-devkitc-1
|
||||||
|
|
||||||
|
[env:perf-test]
|
||||||
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.10-rc1/platform-espressif32.zip
|
||||||
|
build_flags = ${env.build_flags}
|
||||||
|
-D PERF_TEST=1
|
||||||
|
|
||||||
[env:esp8266]
|
[env:esp8266]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = huzzah
|
board = huzzah
|
||||||
|
Reference in New Issue
Block a user