Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 88989a7

Browse files
Merge pull request #184 from mathieucarbou/readme
update readme on build options
2 parents 079446b + 0ae0f95 commit 88989a7

File tree

3 files changed

+84
-28
lines changed

3 files changed

+84
-28
lines changed

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
1818
- [Changes in this fork](#changes-in-this-fork)
1919
- [Dependencies](#dependencies)
2020
- [Performance](#performance)
21-
- [Important recommendations](#important-recommendations)
21+
- [Important recommendations for build options](#important-recommendations-for-build-options)
2222
- [`AsyncWebSocketMessageBuffer` and `makeBuffer()`](#asyncwebsocketmessagebuffer-and-makebuffer)
2323
- [How to replace a response](#how-to-replace-a-response)
2424
- [How to use Middleware](#how-to-use-middleware)
@@ -48,6 +48,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
4848
- (perf) `setCloseClientOnQueueFull(bool)` which can be set on a client to either close the connection or discard messages but not close the connection when the queue is full
4949
- (perf) `SSE_MAX_QUEUED_MESSAGES` to control the maximum number of messages that can be queued for a SSE client
5050
- (perf) `WS_MAX_QUEUED_MESSAGES`: control the maximum number of messages that can be queued for a Websocket client
51+
- (perf) in-flight buffer control and queue congestion avoidance to help to improve parallel connections handling, high volume data transfers and mitigate poor implemeneted slow user-code callbacks delayes on connctions handling
5152
- (perf) Code size improvements
5253
- (perf) Lot of code cleanup and optimizations
5354
- (perf) Performance improvements in terms of memory, speed and size
@@ -56,7 +57,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
5657

5758
## WARNING: Important notes about future version 4.x
5859

59-
This ESPAsyncWebServer fork is now at version 3.x.
60+
This ESPAsyncWebServer fork is now at version 3.x, where we try to keep the API compatibility with original project as much as possible.
6061

6162
Next version 4.x will:
6263

@@ -68,7 +69,8 @@ So if you need one of these feature, you will have to stick with 3.x or another
6869

6970
## Dependencies
7071

71-
**WARNING** The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations, but its name had to stay `ESP Async WebServer` in Arduino Registry.
72+
> [!WARNING]
73+
> The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations, but its name had to stay `ESP Async WebServer` in Arduino Registry.
7274
7375
**PlatformIO / pioarduino:**
7476

@@ -158,26 +160,41 @@ Test is running for 20 seconds with 10 connections.
158160
// Total: 2038 events, 509.50 events / second
159161
```
160162

161-
## Important recommendations
163+
## Important recommendations for build options
162164

163-
Most of the crashes are caused by improper configuration of the library for the project.
164-
Here are some recommendations to avoid them.
165+
Most of the crashes are caused by improper use or configuration of the AsyncTCP library used for the project.
166+
Here are some recommendations to avoid them and build-time flags you can change.
167+
168+
`CONFIG_ASYNC_TCP_MAX_ACK_TIME` - defines a timeout for TCP connection to be considered alive when waiting for data.
169+
In some bad network conditions you might consider increasing it.
170+
171+
`CONFIG_ASYNC_TCP_QUEUE_SIZE` - defines the length of the queue for events related to connections handling.
172+
Both the server and AsyncTCP library in this fork were optimized to control the queue automatically. Do NOT try blindly increasing the queue size, it does not help you in a way you might think it is. If you receive debug messages about queue throttling, try to optimize your server callbaks code to execute as fast as possible.
173+
Read #165 thread, it might give you some hints.
174+
175+
`CONFIG_ASYNC_TCP_RUNNING_CORE` - CPU core thread affinity that runs the queue events handling and executes server callbacks. Default is ANY core, so it means that for dualcore SoCs both cores could handle server activities. If your server's code is too heavy and unoptimized or you see that sometimes
176+
server might affect other network activities, you might consider to bind it to the same core that runs Arduino code (1) to minimize affect on radio part. Otherwise you can leave the default to let RTOS decide where to run the thread based on priority
177+
178+
`CONFIG_ASYNC_TCP_STACK_SIZE` - stack size for the thread that runs sever events and callbacks. Default is 16k that is a way too much waste for well-defined short async code or simple static file handling. You might want to cosider reducing it to 4-8k to same RAM usage. If you do not know what this is or not sure about your callback code demands - leave it as default, should be enough even for very hungry callbacks in most cases.
179+
180+
> [!NOTE]
181+
> This relates to ESP32 only, ESP8266 uses different ESPAsyncTCP lib that does not has this build options
165182
166183
I personally use the following configuration in my projects:
167184

168185
```c++
169-
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
170-
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
171-
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
172-
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as the app (default is core 0)
173-
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
186+
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
187+
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
188+
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
189+
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as Arduino app (default is any core)
190+
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
174191
```
175192

176193
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
177194

178-
The fork from `yubox-node-org` introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
195+
The fork from [yubox-node-org](https://github.com/yubox-node-org/ESPAsyncWebServer) introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
179196

180-
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
197+
This fork is compatible with the original library from [me-no-dev](https://github.com/me-no-dev/ESPAsyncWebServer) regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
181198
So you have the choice of which API to use.
182199

183200
Here are examples for serializing a Json document in a websocket message buffer:
@@ -298,8 +315,17 @@ myHandler.addMiddleware(&authMiddleware); // add authentication to a specific ha
298315
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.
299316
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).
300317

301-
## Original Documentation
302318

319+
## Maintainers
320+
This fork of ESPAsyncWebServer and dependend libs are maintained as an opensource project at best effort level.
321+
- [Mathieu Carbou](https://github.com/mathieucarbou)
322+
- [Emil Muratov](https://github.com/vortigont)
323+
324+
Thanks to all who contributed by providing PRs, testing and reporting issues.
325+
326+
327+
## Original Documentation
328+
<!-- no toc -->
303329
- [Why should you care](#why-should-you-care)
304330
- [Important things to remember](#important-things-to-remember)
305331
- [Principles of operation](#principles-of-operation)

docs/index.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
1818
- [Changes in this fork](#changes-in-this-fork)
1919
- [Dependencies](#dependencies)
2020
- [Performance](#performance)
21-
- [Important recommendations](#important-recommendations)
21+
- [Important recommendations for build options](#important-recommendations-for-build-options)
2222
- [`AsyncWebSocketMessageBuffer` and `makeBuffer()`](#asyncwebsocketmessagebuffer-and-makebuffer)
2323
- [How to replace a response](#how-to-replace-a-response)
2424
- [How to use Middleware](#how-to-use-middleware)
@@ -48,6 +48,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
4848
- (perf) `setCloseClientOnQueueFull(bool)` which can be set on a client to either close the connection or discard messages but not close the connection when the queue is full
4949
- (perf) `SSE_MAX_QUEUED_MESSAGES` to control the maximum number of messages that can be queued for a SSE client
5050
- (perf) `WS_MAX_QUEUED_MESSAGES`: control the maximum number of messages that can be queued for a Websocket client
51+
- (perf) in-flight buffer control and queue congestion avoidance to help to improve parallel connections handling, high volume data transfers and mitigate poor implemeneted slow user-code callbacks delayes on connctions handling
5152
- (perf) Code size improvements
5253
- (perf) Lot of code cleanup and optimizations
5354
- (perf) Performance improvements in terms of memory, speed and size
@@ -56,7 +57,7 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
5657

5758
## WARNING: Important notes about future version 4.x
5859

59-
This ESPAsyncWebServer fork is now at version 3.x.
60+
This ESPAsyncWebServer fork is now at version 3.x, where we try to keep the API compatibility with original project as much as possible.
6061

6162
Next version 4.x will:
6263

@@ -68,7 +69,8 @@ So if you need one of these feature, you will have to stick with 3.x or another
6869

6970
## Dependencies
7071

71-
**WARNING** The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations, but its name had to stay `ESP Async WebServer` in Arduino Registry.
72+
> [!WARNING]
73+
> The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations, but its name had to stay `ESP Async WebServer` in Arduino Registry.
7274
7375
**PlatformIO / pioarduino:**
7476

@@ -158,26 +160,41 @@ Test is running for 20 seconds with 10 connections.
158160
// Total: 2038 events, 509.50 events / second
159161
```
160162

161-
## Important recommendations
163+
## Important recommendations for build options
162164

163-
Most of the crashes are caused by improper configuration of the library for the project.
164-
Here are some recommendations to avoid them.
165+
Most of the crashes are caused by improper use or configuration of the AsyncTCP library used for the project.
166+
Here are some recommendations to avoid them and build-time flags you can change.
167+
168+
`CONFIG_ASYNC_TCP_MAX_ACK_TIME` - defines a timeout for TCP connection to be considered alive when waiting for data.
169+
In some bad network conditions you might consider increasing it.
170+
171+
`CONFIG_ASYNC_TCP_QUEUE_SIZE` - defines the length of the queue for events related to connections handling.
172+
Both the server and AsyncTCP library in this fork were optimized to control the queue automatically. Do NOT try blindly increasing the queue size, it does not help you in a way you might think it is. If you receive debug messages about queue throttling, try to optimize your server callbaks code to execute as fast as possible.
173+
Read #165 thread, it might give you some hints.
174+
175+
`CONFIG_ASYNC_TCP_RUNNING_CORE` - CPU core thread affinity that runs the queue events handling and executes server callbacks. Default is ANY core, so it means that for dualcore SoCs both cores could handle server activities. If your server's code is too heavy and unoptimized or you see that sometimes
176+
server might affect other network activities, you might consider to bind it to the same core that runs Arduino code (1) to minimize affect on radio part. Otherwise you can leave the default to let RTOS decide where to run the thread based on priority
177+
178+
`CONFIG_ASYNC_TCP_STACK_SIZE` - stack size for the thread that runs sever events and callbacks. Default is 16k that is a way too much waste for well-defined short async code or simple static file handling. You might want to cosider reducing it to 4-8k to same RAM usage. If you do not know what this is or not sure about your callback code demands - leave it as default, should be enough even for very hungry callbacks in most cases.
179+
180+
> [!NOTE]
181+
> This relates to ESP32 only, ESP8266 uses different ESPAsyncTCP lib that does not has this build options
165182
166183
I personally use the following configuration in my projects:
167184

168185
```c++
169-
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
170-
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
171-
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
172-
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as the app (default is core 0)
173-
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
186+
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
187+
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
188+
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
189+
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as Arduino app (default is any core)
190+
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
174191
```
175192

176193
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
177194

178-
The fork from `yubox-node-org` introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
195+
The fork from [yubox-node-org](https://github.com/yubox-node-org/ESPAsyncWebServer) introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
179196

180-
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
197+
This fork is compatible with the original library from [me-no-dev](https://github.com/me-no-dev/ESPAsyncWebServer) regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
181198
So you have the choice of which API to use.
182199

183200
Here are examples for serializing a Json document in a websocket message buffer:
@@ -298,8 +315,17 @@ myHandler.addMiddleware(&authMiddleware); // add authentication to a specific ha
298315
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.
299316
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).
300317

301-
## Original Documentation
302318

319+
## Maintainers
320+
This fork of ESPAsyncWebServer and dependend libs are maintained as an opensource project at best effort level.
321+
- [Mathieu Carbou](https://github.com/mathieucarbou)
322+
- [Emil Muratov](https://github.com/vortigont)
323+
324+
Thanks to all who contributed by providing PRs, testing and reporting issues.
325+
326+
327+
## Original Documentation
328+
<!-- no toc -->
303329
- [Why should you care](#why-should-you-care)
304330
- [Important things to remember](#important-things-to-remember)
305331
- [Principles of operation](#principles-of-operation)

library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"name": "Mathieu Carbou",
1717
"maintainer": true
18+
},
19+
{
20+
"name": "Emil Muratov",
21+
"maintainer": true
1822
}
1923
],
2024
"license": "LGPL-3.0",

0 commit comments

Comments
 (0)