From ba3fa2a2ca32dfa0e59f35e7af9bf64d86d9c671 Mon Sep 17 00:00:00 2001 From: Emil Muratov Date: Tue, 10 Dec 2024 22:59:08 +0900 Subject: [PATCH 1/2] throttle polling events when message queue gets filled up a proof of concept, might help on long/large responces with user callbacks (cherry picked from commit 18bbb3318547bde7a34a84229227ea1f5b80cc72) --- src/AsyncTCP.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index 84a87ac..c8eb60b 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -302,6 +302,10 @@ static int8_t _tcp_connected(void * arg, tcp_pcb * pcb, int8_t err) { } static int8_t _tcp_poll(void * arg, struct tcp_pcb * pcb) { + // throttle polling events queing when event queue is getting filled up, let it handle _onack's + if (uxQueueMessagesWaiting(_async_queue) > (rand() % CONFIG_ASYNC_TCP_QUEUE_SIZE / 2 + CONFIG_ASYNC_TCP_QUEUE_SIZE / 4) ) + return ERR_OK; + //ets_printf("+P: 0x%08x\n", pcb); lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t)); e->event = LWIP_TCP_POLL; From 8302dba2b8cf409fbd8882cf7df1c661bec77f1f Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 11 Dec 2024 10:37:39 +0100 Subject: [PATCH 2/2] Issue 169 --- src/AsyncTCP.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index c8eb60b..15338e8 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -303,8 +303,10 @@ static int8_t _tcp_connected(void * arg, tcp_pcb * pcb, int8_t err) { static int8_t _tcp_poll(void * arg, struct tcp_pcb * pcb) { // throttle polling events queing when event queue is getting filled up, let it handle _onack's - if (uxQueueMessagesWaiting(_async_queue) > (rand() % CONFIG_ASYNC_TCP_QUEUE_SIZE / 2 + CONFIG_ASYNC_TCP_QUEUE_SIZE / 4) ) + if (uxQueueMessagesWaiting(_async_queue) > (rand() % CONFIG_ASYNC_TCP_QUEUE_SIZE / 2 + CONFIG_ASYNC_TCP_QUEUE_SIZE / 4) ) { + log_d("throttling"); return ERR_OK; + } //ets_printf("+P: 0x%08x\n", pcb); lwip_event_packet_t * e = (lwip_event_packet_t *)malloc(sizeof(lwip_event_packet_t));