Increase max LWIP sockets on ESP32-S3 #6021
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes the max socket limit from 4 to 8, implementing one of the improvements enabled by the 192KB increase in internal SRAM in the ESP32-S3 compared to the ESP32-S2, as discussed in issue #5915.
Sockets are memory-intensive, and memory use appears to be somewhat non-linear, and somewhat variable based on the socket use.
ESP32-S2
On ESP32-S2 (
Adafruit CircuitPython 7.2.0-alpha.2 on 2022-02-11; ESP32-S2-DevKitC-1-N4R2 with ESP32S2
), fresh memory stats on reset are:Launching code.py and connecting to wifi brings IDF memory down to:
With a max socket limit of 4 on ESP32-S2 (TLS connections each use two sockets), a first TLS connection brings the memory down to:
and adding a second simultaneous TLS connection bring the memory down to:
Pretty slim margin, but it works. It is possible to run out of IDF memory with two TLS connections, resulting in memory exception (or sometimes an
OSError: Failed SSL handshake
, which can arise when there's not enough memory to complete the certificate transaction).ESP32-S3 baseline
On ESP32-S3 (
Adafruit CircuitPython 7.2.0-alpha.2 on 2022-02-11; ESP32-S3-DevKitC-1-N8R2 with ESP32S3
), fresh memory stats on reset are:Launching code.py and connecting to wifi brings IDF memory down to:
Sequential stats after running one, then two, simultaneous TLS sockets, as above:
Plenty of headroom.
ESP32-S3 with PR
On ESP32-S3 with PR (
Adafruit CircuitPython 7.2.0-alpha.2-8-gddac37add-dirty on 2022-02-11; ESP32-S3-DevKitC-1-N8R2 with ESP32S3
), fresh memory stats on reset are:Launching code.py and connecting to wifi brings IDF memory down to:
Now, on the modified ESP32-S3 ,
Allowing up to 8 sockets (or 4 TLS connections), sequential stats after each TLS connection is running are as follows:
Still an order of magnitude more headroom than in the ESP32-S2 case, and uses only about half of the 192KB increase in internal SRAM, leaving room for other features such as increasing the
CIRCUITPY_PYSTACK_SIZE
.Much like with CircuitPython heap memory, users will need to balance the use of IDF memory between any aggressive uses such as these increased socket connections, larger numbers of wifi AP connections, and perhaps some memory-intensive BLE features in the future.