Chapter 4. API Guides
Maximum throughput
Espressif tests ESP-IDF TCP/IP throughput using the wifi/iperf example in an RF sealed enclosure.
The wifi/iperf/sdkconfig.defaults file for the iperf example contains settings known to maximize TCP/IP throughput,
usually at the expense of higher RAM usage. To get maximum TCP/IP throughput in an application at the expense
of other factors then suggest applying settings from this file into the project sdkconfig.
Important: Suggest applying changes a few at a time and checking the performance each time with a particular
application workload.
• If a lot of tasks are competing for CPU time on the system, consider that the lwIP task has configurable CPU
affinity (CONFIG_LWIP_TCPIP_TASK_AFFINITY) and runs at fixed priority ESP_TASK_TCPIP_PRIO
(18). Configure competing tasks to be pinned to a different core, or to run at a lower priority. See also
Built-In Task Priorities.
• If using select() function with socket arguments only, setting CONFIG_LWIP_USE_ONLY_LWIP_SELECT
will make select() calls faster.
• If there is enough free IRAM, select CONFIG_LWIP_IRAM_OPTIMIZATION to improve TX/RX throughput
If using a Wi-Fi network interface, please also refer to Wi-Fi Buffer Usage.
Minimum latency
Except for increasing buffer sizes, most changes which increase throughput will also decrease latency by reducing the
amount of CPU time spent in lwIP functions.
• For TCP sockets, lwIP supports setting the standard TCP_NODELAY flag to disable Nagle’s algorithm.
Minimum RAM usage
Most lwIP RAM usage is on-demand, as RAM is allocated from the heap as needed. Therefore, changing lwIP
settings to reduce RAM usage may not change RAM usage at idle but can change it at peak.
• Reducing CONFIG_LWIP_MAX_SOCKETS reduces the maximum number of sockets in the system. This will
also cause TCP sockets in the WAIT_CLOSE state to be closed and recycled more rapidly (if needed to open
a new socket), further reducing peak RAM usage.
• Reducing CONFIG_LWIP_TCPIP_RECVMBOX_SIZE, CONFIG_LWIP_TCP_RECVMBOX_SIZE and CON-
FIG_LWIP_UDP_RECVMBOX_SIZE reduce memory usage at the expense of throughput, depending on usage.
• Disable CONFIG_LWIP_IPV6 can save about 39 KB for firmware size and 2KB RAM when system power up
and 7KB RAM when TCPIP stack running. If there is no requirement for supporting IPV6 then it can be
disabled to save flash and RAM footprint.
If using Wi-Fi, please also refer to Wi-Fi Buffer Usage.
Peak Buffer Usage The peak heap memory that lwIP consumes is the theoretically-maximum memory that the
lwIP driver consumes. Generally, the peak heap memory that lwIP consumes depends on:
• the memory required to create a UDP connection: lwip_udp_conn
• the memory required to create a TCP connection: lwip_tcp_conn
• the number of UDP connections that the application has: lwip_udp_con_num
• the number of TCP connections that the application has: lwip_tcp_con_num
• the TCP TX window size: lwip_tcp_tx_win_size
• the TCP RX window size: lwip_tcp_rx_win_size
So, the peak heap memory that the LwIP consumes can be calculated with the following formula:
lwip_dynamic_peek_memory = (lwip_udp_con_num * lwip_udp_conn) + (lwip_tcp_con_num *
(lwip_tcp_tx_win_size + lwip_tcp_rx_win_size + lwip_tcp_conn))
Espressif Systems 1431
Submit Document Feedback
Release v4.4