Bug 49276 - mod_cgi allocates unnecessary amounts of memory
Summary: mod_cgi allocates unnecessary amounts of memory
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_cgi (show other bugs)
Version: 2.2.15
Hardware: Sun Solaris
: P2 minor (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: FixedInTrunk
Depends on:
Reported: 2010-05-12 09:24 UTC by Andreas Krennmair
Modified: 2012-02-26 17:04 UTC (History)
0 users

patch to reduce memory usage of mod_cgi. (1.37 KB, patch)
2010-05-12 09:24 UTC, Andreas Krennmair
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Krennmair 2010-05-12 09:24:05 UTC
The function cgi_read_stdout() in mod_cgi allocates unnecessary amounts of memory. For every call of apr_file_read(), APR_BUCKET_BUFF_SIZE (currently 8000) bytes of memory are allocated, even when apr_file_read() delivers only a fraction of the requested amount of data. In practice, this can lead to hugely inflated httpd processes. The attached patch reduces this problem by allocating only as much memory as necessary.
Comment 1 Andreas Krennmair 2010-05-12 09:24:59 UTC
Created attachment 25431 [details]
patch to reduce memory usage of mod_cgi.
Comment 2 Stefan Fritsch 2010-05-13 08:10:57 UTC
Your patch causes all output from the cgi to be copied again, which is not really efficient.

Besides, the memory of the bucket should be freed as soon as the data has been sent over the network. I guess what you are really seeing is one of the memory usage issues fixed in r821471 in trunk.

You could try if the content_length_filter and chunk_filter parts of r821471 fix your problem. It's


and the first three hunks of


I haven't checked if it applies cleanly to 2.2.x, though.
Comment 3 Stefan Fritsch 2011-06-15 23:13:03 UTC
The memory usage of mod_cgi is constant in trunk, even if the cgi streams large amounts of data.
Comment 4 Stefan Fritsch 2012-02-26 17:04:20 UTC
2.4.1 is released, closing.
If you find additional issues in 2.4.x, please re-open.