Skip to content

CONFIG_LWIP_MAX_SOCKETS=10 is too small #5699

Closed
@BbIKTOP

Description

@BbIKTOP

Well, I'm trying to make a HAP device with the Espressif hap, Espressif arduino and Espressif idf.
The problem I experienced is:

  1. Default CONFIG_LWIP_MAX_SOCKETS is set to 10
  2. No lwip sources provided with arduino core
  3. Homekit opens a persistent connection to each client. So, in average family, there are 10-15 devices connected simultaneously. I tested with my own 6 and ran into this problem.
  4. I also use WebServer (which built on WiFiServer), and by default it consumes, as far as I remember, 5 sockets. But no matter, even without the WiFiServer it is a problem, because 7 connected HAP clients surely ain't enough for real purposes. So, in my case, with the default configuration and 6 connected hap clients, any access to the WiFiServer leads to lwip_accept fails with errno 23.

It's a bit strange, that Espressif products don't work together. Even more, the main esp32's advantage is the networking, but 10 sockets is just a joke in this sense.

Proposed fixes:

  1. Include lwip sources, so any user could configure the required sockets amount and range (not default 1-16, but more reasonable 1-20 or maybe 1-30 as lwip has no such limit)
    It would probably lead to the need to add the whole IDF sources, but I'm not sure

  2. Include different precompiled liblwip.a versions, like with 10 (current value), 16 (current menuconfig max value) and 20 or even 30 CONFIG_LWIP_MAX_SOCKETS

Maybe you could propose better, I don't know, sorry.

Activity

BbIKTOP

BbIKTOP commented on Sep 24, 2021

@BbIKTOP
Author

Found also, that httpd_server performs an explicit check of this setting, so, it should be recompiled as well. Also, set the limit to 20, everything is working fine so far. It’s definitely needs to be changed

added this to the 2.0.1 milestone on Sep 29, 2021
me-no-dev

me-no-dev commented on Sep 29, 2021

@me-no-dev
Member

@SuGlider please check memory usage if that value changes to 16 as part of your memory investigations :)

me-no-dev

me-no-dev commented on Sep 29, 2021

@me-no-dev
Member

@david-cermak mind giving your two cents? :)

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

@SuGlider please check memory usage if that value changes to 16 as part of your memory investigations :)

already did:

After some settlement period, with 20 sockets:

Memory usage: : Total heap: 322999, free heap: 84043, total himem 4191995, free himem 3092611

and with default 10 sockets

Memory usage: : Total heap: 323747, free heap: 86575, total himem 4191947, free himem 3092395

So, the difference is about 2kb per 10 sockets. Sorry, didn't test it with 16, but I suppose the result will be quite close to 20 ;)

SuGlider

SuGlider commented on Sep 29, 2021

@SuGlider
Collaborator

Ok. So this is the Heap with nothing running on the ESP32.

What about when the application opens and uses all those sockets?

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

This is with esp-hap and webserver and 6 hap clients connected

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

With 16 sockets after 6 minutes:

Memory usage: : Total heap: 323819, free heap: 86675, total himem 4191971, free himem 3092503

So, I suppose 20 is ok, but would require custom idf with redefined max value in the esp-idf/components/lwip/Kconfig

    config LWIP_MAX_SOCKETS
        int "Max number of open sockets"
        range 1 16
        default 16
        help
            Sockets take up a certain amount of memory, and allowing fewer
            sockets to be open at the same time conserves memory. Specify
            the maximum amount of sockets here. The valid value is from 1
            to 16.

As the least thing to do, it would be good to set it to at least 16. 20 would be better, for sure, but I understand it is too much complicated to implement )))) So, please, make it at least 16.

Btw, 14 minutes uptime, 16 sockets max, the same app:

Memory usage: : Total heap: 323783, free heap: 86611, total himem 4191947, free himem 3092395
SuGlider

SuGlider commented on Sep 29, 2021

@SuGlider
Collaborator

Is this running on a ESP32WROVER with PSRAM, right?

Although it seems that himem allocation changes almost nothing, would it change heap allocation in a plain ESP32WROOM (no PSRAM)?

Can you test it as well, please?

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

I have A LOT of psram allocations for my objects, like peripheral drivers, events, etc, it's really difficult to change everywhere, and I suppose it won't affect the result. As I have a pool allocator for psram and my objects use almost 1mb of it, I'd need to rewrite it to the standard alloc/free. I could try, if you insist, but really, do you think it matters? Arduino and idf both don't use psram, so its just me who does.

SuGlider

SuGlider commented on Sep 29, 2021

@SuGlider
Collaborator

Ok. Most probably nothing will really change. Some IDF 4.4 drivers allow to use PSRAM for buffers and queues, I but think this is disabled for Arduino.

All right, thus, your suggestion/request is to increase MAX SOCKETS in IDF KConfig for LWIP in Arduino for a next release, correct?

Arduino uses a set of IDF components precompiled into a set of libxxx.a which are built from IDF sdkconfig and KConfigs once a new Arduino version is released.

We could consider setting the number of sockets to 20 in LWIP KConfig and make it default in the precompiled library and its header files.

At this time we have people complaining about high heap allocation in new Arduino Core version 2.0.0. I'll have to check how to make room for all those changes and yet free some Heap to users.

An alternative option for you would be build your own library version with all the resources you need and replace the libxxx.a + header files set in your Arduino environment. Not sure if this is something you would like to do...

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

Exactly. At least to 16, as it won't require any changes in the idf cfg. But 20 would be better, of course, it's a network device, isn't it?

SuGlider

SuGlider commented on Sep 29, 2021

@SuGlider
Collaborator

Ok. I'll include this request on the Heap allocation study I'm currently working.

Anyway, I guess that currently you are using a modified liblwip.a with a number sockets you need for your project, right?

BbIKTOP

BbIKTOP commented on Sep 29, 2021

@BbIKTOP
Author

Yes, among with httpd libs, as httpd checks for CONFIG_LWIP_MAX_SOCKETS -3 and failed to start if this isn't satisfied: https://github.com/espressif/esp-idf/blob/3e370c4296247b349aa3b9a0076c05b9946d47dc/components/esp_http_server/src/httpd_main.c#L410

19 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    CONFIG_LWIP_MAX_SOCKETS=10 is too small · Issue #5699 · espressif/arduino-esp32