Hi,
trying to reduce httpd memory usage, I've worked on ap_rgetline_core in
protocol.c.
This function gets a line of protocol input.
To do so, :
- it processes the apr_bucket_brigade it is given in parameter, one
bucket at a time
- for the common case, it allocates memory to store the data from
the bucket, with a minimum on 80 bytes, to try to avoid other memory
allocations, should there be other buckets
- in case of several buckets and 80 bytes was not enough, it
doubles the memory allocated and copy data in the new buffer
Why is this minimum of 80 bytes there ?
As stated in the comment, we assume the common case : only 1 bucket.
According to my testing, with a basic configuration and a simple
request, this is the case.
So, I suggest,
* either to simply remove the test line 293 in protocol.c and the
use of MIN_LINE_ALLOC
if (current_alloc < MIN_LINE_ALLOC) {
current_alloc = MIN_LINE_ALLOC;
}
The already in place mechanism will grow the buffer if needed
* or, if you prefer to over allocate in case of several buckets,
turn it into:
if (APR_BUCKET_NEXT(e) != APR_BRIGADE_SENTINEL(bb)) {
if (current_alloc < MIN_LINE_ALLOC) {
current_alloc = MIN_LINE_ALLOC;
}
}
to save memory when we know we can.
Personally, I prefer the first version and drop the test and the use of
MIN_LINE_ALLOC.
Here is a example of the calls to ap_rgetline_core to process a request.
In all cases, only 1 bucket was in the brigade.
If we allocated only what was needed, *416 bytes* would have been saved,
which is, IMO, not to bad:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
---> ap_rgetline_core : 16 < 80 ? (only one bucket)
--> 'GET / HTTP/1.1'
---> ap_rgetline_core : 17 < 80 ? (only one bucket)
--> 'Host: localhost'
---> ap_rgetline_core : 88 < 80 ? No, allocate 88 (only one bucket)
--> 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0)
Gecko/20100101 Firefox/20.0'
---> ap_rgetline_core : 73 < 80 ? (only one bucket)
--> 'Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
---> ap_rgetline_core : 54 < 80 ? (only one bucket)
--> 'Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
---> ap_rgetline_core : 32 < 80 ? (only one bucket)
--> 'Accept-Encoding: gzip, deflate'
---> ap_rgetline_core : 24 < 80 ? (only one bucket)
--> 'Connection: keep-alive'
---> ap_rgetline_core : 18 < 80 ? (only one bucket)
--> 'Pragma: no-cache'
---> ap_rgetline_core : 25 < 80 ? (only one bucket)
--> 'Cache-Control: no-cache'
---> ap_rgetline_core : 2 < 80 ? (only one bucket)
--> ''
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Thanks for your comments.
best regards,
CJ