curl-library
Memory usage
Date: Wed, 22 Dec 2010 12:05:34 -0800 (PST)
Hi all,
I wrote a simple program to reproduce something I have been seeing. If I run
the program and execute the loop a lot of times the memory usage spikes. I ran
it under massif and after a while the memory usage was very large:
32129 root 20 0 350m 327m 4096 S 0.0 33.7 13:54.78 massif
Massif shows that a lot of the memory is here:
->68.88% (70,327,358B) 0x452920A: PR_Calloc (in /lib/libnspr4.so)
| ->67.40% (68,821,549B) 0x4D4DB1E: nss_ZAlloc (arena.c:892)
| | ->28.87% (29,480,256B) 0x4D3D112: pem_CreateObject (pobject.c:1154)
| | | ->28.87% (29,480,256B) 0x4D3EA0C: pem_mdSession_CreateObject
(psession.c:157)
| | | ->28.87% (29,480,256B) 0x4D42B54: nssCKFWSession_CreateObject
(session.c:1353)
| | | ->28.87% (29,480,256B) 0x4D49B76: NSSCKFWC_CreateObject (wrap.c:1991)
| | | ->28.87% (29,480,256B) 0x4D3A49A: pemC_CreateObject (nssck.api:566)
| | | ->28.87% (29,480,256B) 0x440A7BF: PK11_CreateNewObject
(pk11obj.c:412)
| | | ->28.87% (29,480,256B) 0x440AA5E: PK11_CreateGenericObject
(pk11obj.c:1347)
| | | ->28.87% (29,480,256B) 0x406D254: (within
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x406EA31: Curl_nss_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x4064A60: Curl_ssl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x40438D7: Curl_http_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x404B12C:
Curl_protocol_connect (in /usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x405038D: Curl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x4059002: Curl_perform (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x4059DB1:
curl_easy_perform (in /usr/lib/libcurl.so.4.1.1)
| | | ->28.87% (29,480,256B) 0x804878C: main (in
/root/curltest)
| | |
| | ->28.64% (29,242,512B) 0x4D3D1E5: pem_CreateObject (pobject.c:1146)
| | | ->28.64% (29,242,512B) 0x4D3EA0C: pem_mdSession_CreateObject
(psession.c:157)
| | | ->28.64% (29,242,512B) 0x4D42B54: nssCKFWSession_CreateObject
(session.c:1353)
| | | ->28.64% (29,242,512B) 0x4D49B76: NSSCKFWC_CreateObject (wrap.c:1991)
| | | ->28.64% (29,242,512B) 0x4D3A49A: pemC_CreateObject (nssck.api:566)
| | | ->28.64% (29,242,512B) 0x440A7BF: PK11_CreateNewObject
(pk11obj.c:412)
| | | ->28.64% (29,242,512B) 0x440AA5E: PK11_CreateGenericObject
(pk11obj.c:1347)
| | | ->28.64% (29,242,512B) 0x406D254: (within
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x406EA31: Curl_nss_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x4064A60: Curl_ssl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x40438D7: Curl_http_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x404B12C:
Curl_protocol_connect (in /usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x405038D: Curl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x4059002: Curl_perform (in
/usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x4059DB1:
curl_easy_perform (in /usr/lib/libcurl.so.4.1.1)
| | | ->28.64% (29,242,512B) 0x804878C: main (in
/root/curltest)
| | |
| | ->07.63% (7,786,640B) 0x4D3CC8C: pem_CreateObject (pobject.c:1099)
| | | ->07.63% (7,786,640B) 0x4D3EA0C: pem_mdSession_CreateObject
(psession.c:157)
| | | ->07.63% (7,786,640B) 0x4D42B54: nssCKFWSession_CreateObject
(session.c:1353)
| | | ->07.63% (7,786,640B) 0x4D49B76: NSSCKFWC_CreateObject (wrap.c:1991)
| | | ->07.63% (7,786,640B) 0x4D3A49A: pemC_CreateObject (nssck.api:566)
| | | ->07.63% (7,786,640B) 0x440A7BF: PK11_CreateNewObject
(pk11obj.c:412)
| | | ->07.63% (7,786,640B) 0x440AA5E: PK11_CreateGenericObject
(pk11obj.c:1347)
| | | ->07.63% (7,786,640B) 0x406D254: (within
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x406EA31: Curl_nss_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x4064A60: Curl_ssl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x40438D7: Curl_http_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x404B12C: Curl_protocol_connect
(in /usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x405038D: Curl_connect (in
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x4059002: Curl_perform (in
/usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x4059DB1:
curl_easy_perform (in /usr/lib/libcurl.so.4.1.1)
| | | ->07.63% (7,786,640B) 0x804878C: main (in
/root/curltest)
The code to do this is below. Note that if I do not set FORBID_REUSE there
seems to be no issue. I've used a few different https urls and see the same
issue. I've tried https://www.yahoo.com and https://www.facebook.com. The
issue does not happen if I use a non https url.
#include <stdio.h>
#include <curl/curl.h>
int main(int argc, char ** argv)
{
CURL *curl;
CURLcode res;
int i=0;
int runcount=0;
if (argc < 2)
{
printf ("Usage: %s runcount\n", argv[0]);
return 1;
}
else
{
runcount = atoi(argv[1]);
}
curl_global_init(CURL_GLOBAL_ALL);
for (i=0; i<runcount; i++)
{
curl = curl_easy_init();
if (!curl)
{
printf ("Failed to allocate curl handle");
break;
}
curl_easy_setopt(curl, CURLOPT_URL, "INSERT_AN_HTTPS_URL");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
printf ("Call to curl_easy_perform failed");
break;
}
else
{
printf ("Iteration %d", i);
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
Is there some kind of cleanup function or flag that I can set that will
alleviate this? The FORBID_REUSE just illustrates the behavior I am seeing with
the server that I need to communicate with. It causes me to always close the
connection.
Thanks,
Kevin
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-12-22