Task Lag using TCP with both LwIP and sockets.

DesignerRick
Posts: 7
Joined: Sun May 14, 2017 8:45 am

Task Lag using TCP with both LwIP and sockets.

Postby DesignerRick » Thu Jan 06, 2022 1:07 pm

Using IDF v4.3.1 I have implemented a simple http server to output debug information from a project using the ESP32.

The ESP32 is connected to a router, with a good connection.

The web-page has a 500ms refresh to show real time values updating on a simple web page.

Initially I thought it was working great then realised I have an issue where intermittently (about every 50 seconds) the web-server task hangs from 5 to 20 seconds then catches up again causing a refresh lag on the web page.

I have tried using sockets and LwIP, they both have the same issue. I have set the TCP_NODELAY and also tried turning off the WiFi AMPDU (TX and RX). Tried adjusting the number of WiFi RX/TX buffers and the buffer sizes, tried static and dynamic.

I have tried setting the task priority, the task stack size and even ran it on different cores. Nothing seems to change this. It happens on Chrome and Explorer... I have tried a 2000ms refresh this does not affect the issue.

Below is a sample output with one task outputting the time every second, the webserver task showing socket listening and accepted. You can see the webserver task freeze for 15 seconds then it does a massive catch-up. There are no error codes.

There is no point in posting code as this output is using the example tcp server in IDF 4.3

I also think I have a similar problem using UDP on another project.....
  • I (12:41:52.484) dts: Time is Thu Jan 6 12:41:52 2022
    I (12:41:52.562) WebServer: Socket accepted ip address: 192.168.1.33
    I (12:41:52.567) WebServer: Socket listening
    I (12:41:53.179) WebServer: Socket accepted ip address: 192.168.1.33
    I (12:41:53.183) WebServer: Socket listening
    I (12:41:53.481) dts: Time is Thu Jan 6 12:41:53 2022
    I (12:41:53.489) WebServer: Socket accepted ip address: 192.168.1.33
    I (12:41:53.493) WebServer: Socket listening
    I (12:41:54.105) WebServer: Socket accepted ip address: 192.168.1.33
    I (12:41:54.109) WebServer: Socket listening
    I (12:41:54.484) dts: Time is Thu Jan 6 12:41:54 2022
    I (12:41:55.484) dts: Time is Thu Jan 6 12:41:55 2022
    I (12:41:56.484) dts: Time is Thu Jan 6 12:41:56 2022
    I (12:41:57.484) dts: Time is Thu Jan 6 12:41:57 2022
    I (12:41:58.484) dts: Time is Thu Jan 6 12:41:58 2022
    I (12:41:59.484) dts: Time is Thu Jan 6 12:41:59 2022
    I (12:42:00.484) dts: Time is Thu Jan 6 12:42:00 2022
    I (12:42:01.484) dts: Time is Thu Jan 6 12:42:01 2022
    I (12:42:02.484) dts: Time is Thu Jan 6 12:42:02 2022
    I (12:42:03.484) dts: Time is Thu Jan 6 12:42:03 2022
    I (12:42:04.484) dts: Time is Thu Jan 6 12:42:04 2022
    I (12:42:05.484) dts: Time is Thu Jan 6 12:42:05 2022
    I (12:42:06.484) dts: Time is Thu Jan 6 12:42:06 2022
    I (12:42:07.484) dts: Time is Thu Jan 6 12:42:07 2022
    I (12:42:08.484) dts: Time is Thu Jan 6 12:42:08 2022
    I (12:42:09.484) dts: Time is Thu Jan 6 12:42:09 2022
    I (12:42:09.767) WebServer: Socket accepted ip address: 192.168.1.33
    I (12:42:09.771) WebServer: Socket listening
    I (12:42:09.789) WebServer: Socket accepted ip address: 192.168.1.33
has anyone else had this issue.

DesignerRick
Posts: 7
Joined: Sun May 14, 2017 8:45 am

Re: Task Lag using TCP with both LwIP and sockets.

Postby DesignerRick » Mon Mar 14, 2022 9:47 am

The cause of this lag was me collecting RSSI every 10 seconds. I reduced the collection to 5 minutes and the lag went away.

wifi_ap_record_t ap;
esp_wifi_sta_get_ap_info(&ap);

Who is online

Users browsing this forum: No registered users and 15 guests