You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Christophe JAILLET <ch...@wanadoo.fr> on 2013/03/25 21:27:13 UTC
[PATCH] Reduce apr_[i|l|off_t_]toa memory footprint for common cases
Hi list,
I'm currently trying to reduce httpd memory footprint.
(http://www.mail-archive.com/dev@httpd.apache.org/msg56558.html)
On my test machine, processing a request requires about 15ko in the
'request' pool. I'm trying to reduce it to only use 8k which is the
minimum allocated on Linux (min: 2 x 4ko pages)
As a first step, I noticed that apr_itoa, apr_ltoa, apr_off_t_toa could
be tweaked to require less memory for some common cases.
The attached patch reduces memory use for small values, that is to say
for strings that fit in 8 bytes (including NULL)
On my system:
apr_itoa allocates 14 (4*3+2) bytes, which gets rounded to 16. A common
use is for HTTP status code which fits in much less.
--> 8 bytes can be saved in the request pool
apr_off_t_toa allocates 26 (8*3+2) bytes, which gets rounded to 32. A
common use is for the length of the answer. Common pages are well under
9.999.999 bytes.
--> 24 bytes can be saved in the request pool
This is not that much, but is a start.
Best regards,
CJ
Re: [PATCH] Reduce apr_[i|l|off_t_]toa memory footprint for common cases
Posted by Jeff Trawick <tr...@gmail.com>.
On Mon, Apr 1, 2013 at 6:21 AM, Christophe JAILLET <
christophe.jaillet@wanadoo.fr> wrote:
> Le 28/03/2013 19:32, Jeff Trawick a écrit :
>
> On Thu, Mar 28, 2013 at 1:38 PM, Stefan Fritsch <sf...@sfritsch.de> wrote:
>>
>>> On Monday 25 March 2013, Christophe JAILLET wrote:
>>>
>>>> As a first step, I noticed that apr_itoa, apr_ltoa, apr_off_t_toa
>>>> could be tweaked to require less memory for some common cases.
>>>> The attached patch reduces memory use for small values, that is to
>>>> say for strings that fit in 8 bytes (including NULL)
>>>>
>>> Looks like a reasonable optimization to me.
>>>
>>> Cheers,
>>> Stefan
>>>
>> When shrinking it down to 8, why not avoid the apr_palloc altogether?
>> Also, how about lower-casing the name BUFFER_SIZE since it isn't
>> const?
>>
>>
>> I'm not sure it is possible to avoid the call to apr_palloc.
>
You're correct, of course :)
>
> For BUFFER_SIZE, I 100% agree with you. Previously it was a 'const int',
> and I just left it as it was.
>
> There are also some tab vs space possible clean-up in these functions.
>
> Finally, even if the 3 functions work the same way, they have different
> way to write it:
> *--start = '0' + (n % 10);
> *--start = (char)('0' + (n % 10));
> *--start = '0' + (char)(n % 10);
> The 2nd version is, IMO, the best one.
>
preferred by me too
>
> I didn't include it in my patch to reduce the differences.
>
> CJ
>
--
Born in Roswell... married an alien...
http://emptyhammock.com/
Re: [PATCH] Reduce apr_[i|l|off_t_]toa memory footprint for common
cases
Posted by Christophe JAILLET <ch...@wanadoo.fr>.
Le 28/03/2013 19:32, Jeff Trawick a écrit :
> On Thu, Mar 28, 2013 at 1:38 PM, Stefan Fritsch <sf...@sfritsch.de> wrote:
>> On Monday 25 March 2013, Christophe JAILLET wrote:
>>> As a first step, I noticed that apr_itoa, apr_ltoa, apr_off_t_toa
>>> could be tweaked to require less memory for some common cases.
>>> The attached patch reduces memory use for small values, that is to
>>> say for strings that fit in 8 bytes (including NULL)
>> Looks like a reasonable optimization to me.
>>
>> Cheers,
>> Stefan
> When shrinking it down to 8, why not avoid the apr_palloc altogether?
> Also, how about lower-casing the name BUFFER_SIZE since it isn't
> const?
>
>
I'm not sure it is possible to avoid the call to apr_palloc.
For BUFFER_SIZE, I 100% agree with you. Previously it was a 'const int',
and I just left it as it was.
There are also some tab vs space possible clean-up in these functions.
Finally, even if the 3 functions work the same way, they have different
way to write it:
*--start = '0' + (n % 10);
*--start = (char)('0' + (n % 10));
*--start = '0' + (char)(n % 10);
The 2nd version is, IMO, the best one.
I didn't include it in my patch to reduce the differences.
CJ
Re: [PATCH] Reduce apr_[i|l|off_t_]toa memory footprint for common cases
Posted by Jeff Trawick <tr...@gmail.com>.
On Thu, Mar 28, 2013 at 1:38 PM, Stefan Fritsch <sf...@sfritsch.de> wrote:
> On Monday 25 March 2013, Christophe JAILLET wrote:
>> As a first step, I noticed that apr_itoa, apr_ltoa, apr_off_t_toa
>> could be tweaked to require less memory for some common cases.
>> The attached patch reduces memory use for small values, that is to
>> say for strings that fit in 8 bytes (including NULL)
>
> Looks like a reasonable optimization to me.
>
> Cheers,
> Stefan
When shrinking it down to 8, why not avoid the apr_palloc altogether?
Also, how about lower-casing the name BUFFER_SIZE since it isn't
const?
--
Born in Roswell... married an alien...
http://emptyhammock.com/
Re: [PATCH] Reduce apr_[i|l|off_t_]toa memory footprint for common cases
Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 25 March 2013, Christophe JAILLET wrote:
> As a first step, I noticed that apr_itoa, apr_ltoa, apr_off_t_toa
> could be tweaked to require less memory for some common cases.
> The attached patch reduces memory use for small values, that is to
> say for strings that fit in 8 bytes (including NULL)
Looks like a reasonable optimization to me.
Cheers,
Stefan