Using apache 1.3.29
I defined tenbyte_string as the constant string "0123456789" which is 10 bytes long.
Here is a test where I used ap_pstrcat( ... ) to in a loop 10,000 times so the resulting string should only take up 10 * 10,000 = 100,000 bytes.
It took nearly 400 MB in redhat 7.2 and over 1 GB in windows XP
I ran this code on apache 1.3.29 redhat version 7.2 and it used nearly 400 Mega Bytes of RAM, with physical RAM of only 128 MB
When I ran it on windows XP built with MS Visual Studio.NET and it used over 1 Giga Bytes of RAM on a machine with only 384 MB of physical RAM in windows it persisted with over 86 MB of Mem Usage according to Task Manager and over 1 Gigabyte in VM Size according to Task Manager Windows XP never released either the Mem Usage or VM Size. Eventually I got a warning from XP saying I should increase my RAM
I simplified and altered the mod_example source code from the apache 1.3.29 distribution for the test.
Does anybody know why this little loop uses so much RAM? Is there a problem with the way the code is written? Is it possible that apache has a pool problem? Does this repeat in Apache version 2 pools?
The source code follows: ------------------------------------------------------------------------------------------- #define tenbyte_string "0123456789"
static int example_handler(request_rec *r) { int i; pool *subp1, *subp2, *p = r->pool; char *s = "";
r->content_type = "text/html";
ap_soft_timeout("send example call trace", r); ap_send_http_header(r);
/* * If we're only supposed to send header information (HEAD request), we're * already there. */ if (r->header_only) { ap_kill_timeout(r); return OK; }
//ap_rputs(DOCTYPE_HTML_3_2, r);
ap_rprintf(r, "<h2>hello world</h2>");
subp1 = ap_make_sub_pool(p); subp2 = ap_make_sub_pool(p); for (i = 0; i < 10000; i++) { ap_clear_pool(subp1); s = ap_pstrcat(subp1, s, tenbyte_string, NULL); ap_clear_pool(subp2); s = ap_pstrdup(subp2, s); } ap_destroy_pool(subp1); ap_destroy_pool(subp2);
ap_kill_timeout(r);
return OK; }
-------------------------------------------------------------------------------------------
Let me know what everyone thinks.
Mark R. Rowe, MSEE