Enable webserver queue and limits

Enable the new concurrent request and queue size limit features
of AsyncWebServer.  This should improve the handling of burst
traffic or many clients, and significantly reduce the likelihood
of OOM crashes due to HTTP requests.
This commit is contained in:
Will Miles 2024-08-04 14:02:05 -04:00
parent 1df717084b
commit 981750a48a
2 changed files with 20 additions and 3 deletions

View File

@ -560,8 +560,25 @@
#endif
#endif
//#define MIN_HEAP_SIZE (8k for AsyncWebServer)
#define MIN_HEAP_SIZE 8192
//#define MIN_HEAP_SIZE
#define MIN_HEAP_SIZE 2048
// Web server limits
#ifdef ESP8266
// Minimum heap to consider handling a request
#define WLED_REQUEST_MIN_HEAP (8*1024)
// Estimated maximum heap required by any one request
#define WLED_REQUEST_HEAP_USAGE (6*1024)
#else
// ESP32 TCP stack needs much more RAM than ESP8266
// Minimum heap remaining before queuing a request
#define WLED_REQUEST_MIN_HEAP (12*1024)
// Estimated maximum heap required by any one request
#define WLED_REQUEST_HEAP_USAGE (12*1024)
#endif
// Maximum number of requests in queue; absolute cap on web server resource usage.
// Websockets do not count against this limit.
#define WLED_REQUEST_MAX_QUEUE 6
// Maximum size of node map (list of other WLED instances)
#ifdef ESP8266

View File

@ -874,7 +874,7 @@ WLED_GLOBAL bool ledStatusState _INIT(false); // the current LED state
#endif
// server library objects
WLED_GLOBAL AsyncWebServer server _INIT_N(((80)));
WLED_GLOBAL AsyncWebServer server _INIT_N(((80, {0, WLED_REQUEST_MAX_QUEUE, WLED_REQUEST_MIN_HEAP, WLED_REQUEST_HEAP_USAGE})));
#ifdef WLED_ENABLE_WEBSOCKETS
WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws")));
#endif