espressif / esp-mqtt

ESP32 mqtt component
Apache License 2.0
603 stars 255 forks source link

High memory usage(?) when MQTT client is connected with SSL (IDFGH-9993) #91

Closed sysizlayan closed 5 years ago

sysizlayan commented 5 years ago

Hi, I am testing the mqtt communication in my code.

When I initialized the MQTT connection and MQTT_EVENT_CONNECTED event occured, the free heap size reduces around 40KB.

I (4051) K_station: [APP] Heap before Mqtt: 186536 bytes I (5354) wifi: state: init -> auth (b0) I (5356) wifi: Set ps type: 1

I (5356) K_station: Waiting connection.... I (5359) wifi: state: auth -> assoc (0) I (5363) wifi: state: assoc -> run (10) I (5375) wifi: connected with SSID, channel 8 I (5376) wifi: pm start, type: 1

I (5378) K_station: SYSTEM_EVENT_STA_CONNECTED I (6802) K_station: SYSTEM_EVENT_STA_GOT_IP I (6802) K_station: got ip:192.168.1.128

I (7802) K_station: [APP] Heap after Mqtt: 176124 bytes I (7802) Main: [APP] Heap after initialization: 174108 bytes I (7803) Main: [APP] Free memory: 173496 bytes I (9920) K_station: MQTT_EVENT_CONNECTED I (12809) Main: [APP] Free memory: 131952 bytes

Is this kind of memory usage normal? It seems high to me? Thanks in advance.

david-cermak commented 5 years ago

Hi @sysizlayan

Yes, it is about right, one TLS connection consumes about 35k. It is possible to reduce the amount, enabling MBEDTLS_ASYMMETRIC_CONTENT_LEN (under component -> mbedtls in menuconfig) which would reduce approximately 12K. (AFAIK this option will be enabled by default in idf 4.0)

sysizlayan commented 5 years ago

Thanks for the answer :)

VerusLogic commented 1 year ago

Is there a config parameter that sets dynamic memory allocation to internal PSRAM of the ESP32-S2R2?

euripedesrocha commented 1 year ago

@VerusLogic we are adding control to direct outbox allocation to PSRAM. If you have a use case that isn't covered by that option, please open an issue describing your needs for further discussion.