httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Leggett <>
Subject Allocating a buffer efficiently...?
Date Fri, 01 Mar 2002 04:23:52 GMT
Hi all,

In a recent patch to mod_proxy, a static buffer used to store data read
from backend before it was given to frontend was changed to be allocated
dynamically from a pool like so:

+    /* allocate a buffer to store the bytes in */
+    /* make sure it is at least IOBUFSIZE, as recv_buffer_size may be
zero for
system default */
+    buf_size = MAX(recv_buffer_size, IOBUFSIZE);
+    buf = ap_palloc(r->pool, buf_size);

This change allows for a dynamically configurable buffer size, and fixes
the code to be thread safe.

However: it has been pointed out that this new code makes the Apache
footprint significantly larger like so:

> There is one drawback in this code. ap_palloc() is not good for
> big allocations (I think > 16K) because it stores data and meta-data
> together. I had found this when try to allocate memory from pool
> for zlib in mod_deflate. zlib needs about 390K - 2*128K + 2*64K + 6K.
> After this change Apache had grown up about 2M after about hour
> with 50 requests/s. I'm not sure that this growing could continue but
> I did not want additional 2M on each Apache.
> I use malloc for big allocations, store addresses in array
> allocated from pool and set cleanup for this array.
> In cleanup I free addresses if they is not free already.


-----------------------------------------		"There's a moon
					over Bourbon Street
View raw message