Very high memory usage by SSL/TLS functions

rojer
Posts: 12
Joined: Mon Jun 15, 2015 5:51 pm

Very high memory usage by SSL/TLS functions

Postby rojer » Wed Jul 29, 2015 11:31 pm

hi

i'm having trouble using SSL because espconn_secure_connect requires so much RAM.
here is a simple application, that does the bare minimum necessary to fetch https://www.google.com
it has a 10ms timer that prints output of system_get_free_heap_size, and here's what it looks like:

heap free: 41376
wifi event: 3, heap free: 41288 <--- wifi status change callback, parses URL and invokes espconn_gethostbyname
resolving... (hf 38616) <--- immediately before espconn_gethostbyname
ip:192.168.1.84,mask:255.255.255.0,gw:192.168.1.1
heap free: 38520
heap free: 38704
heap free: 38704
heap free: 38704
heap free: 38704
heap free: 38704
heap free: 38704
heap free: 38704
connecting (secure=1, port=443, hf=38664)... <-- immediately before espconn_secure_connect
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 38192
heap free: 29000 <--- !!! -10K in one go
heap free: 29000
heap free: 29000
heap free: 29000
client handshake start.
heap free: 30632
heap free: 30632
heap free: 30632
heap free: 30632
heap free: 30632
heap free: 30632
heap free: 30632
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 30528
heap free: 18616 <--- !!!!!!!!! yum, another 12K, thank you very much
heap free: 18616
heap free: 18616
heap free: 18616
heap free: 18616
heap free: 18616
client handshake ok! <-- printed by SDK
sending request... hf=29784 <-- printed from the connect callback (registered with espconn_regist_connectcb)
heap free: 29824 note that 10k is still allocated, while we're awaiting response, maybe for buffers or something. kinda high if you ask me.
heap free: 29824
heap free: 29824
...


so, as you can see, at its peak, the amount of memory needed just for SSL handshake is almost 20K (38 - 18).
this is nowhere near the value set by espconn_secure_set_size, which is 4096 in my case.
i think this sort of memory usage is unreasonable. there's waste there somewhere...

and, for comparison, here's the same request to http://www.google.com - everything else the same, just removed "s" (which invokes espconn_connect now instead of secure_connect, obviously).

heap free: 41376
wifi event: 3, heap free: 41288
resolving... (hf 38616)
ip:192.168.1.84,mask:255.255.255.0,gw:192.168.1.1
heap free: 38400
heap free: 38704
heap free: 38704
heap free: 38704
connecting (secure=0, port=80, hf=38664)...
heap free: 38192
heap free: 38192
heap free: 38192
sending request... hf=38288
heap free: 36696
heap free: 36696
heap free: 36696
heap free: 36696
heap free: 38368
heap free: 38368
heap free: 38368
recv resp 1095...
response: HTTP/1.0 302 Found
Location: http://www.google.ie/?gws_rd=cr&ei=mva4 ... 7ga0z774CQ
...more headers from google.com here...
heap free: 41344

rojer
Posts: 12
Joined: Mon Jun 15, 2015 5:51 pm

Re: Very high memory usage by SSL/TLS functions

Postby rojer » Wed Aug 05, 2015 10:59 pm

by using a different SSL library i was able to get the memory usage to under 10K

leeshine
Posts: 63
Joined: Wed Dec 31, 2014 4:59 pm

Re: Very high memory usage by SSL/TLS functions

Postby leeshine » Fri Aug 07, 2015 9:14 am

memory usage is a big problem in using ssl, it may cause restart sometimes.

tve
Posts: 123
Joined: Sun Feb 15, 2015 4:33 pm

Re: Very high memory usage by SSL/TLS functions

Postby tve » Fri Aug 07, 2015 12:33 pm

rojer wrote:by using a different SSL library i was able to get the memory usage to under 10K

Which SSL library did you use?

mvsespressif
Posts: 1
Joined: Mon Jun 19, 2017 3:03 pm

Re: Very high memory usage by SSL/TLS functions

Postby mvsespressif » Mon Jun 19, 2017 3:08 pm

rojer wrote:by using a different SSL library i was able to get the memory usage to under 10K

Hi,
An you please let me know the SSL library you used with low memory usage?

Who is online

Users browsing this forum: No registered users and 8 guests