AlfaProject has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I'm working on ad-system.
I need to minimize the footprint of the httpd processes .
Now I'm using apache prefork+mod_perl perlRun, each process takes around 15M in RES(top).
What I can do to reduce httpd size or just move to another technology that uses less memory ?
Thanks

Replies are listed 'Best First'.
Re: How to minimize memory footprint
by zwon (Abbot) on Oct 24, 2011 at 12:33 UTC

    Note, that some of these 15M are shared between processes due to Copy-on-write, if you preloading modules on startup amount of memory shared between processes will increase. Also I had good results with nginx + Starman.

    PS: and there are some notes in the mod_perl documentation.

    PPS: I saw in many places people run one apache with mod_perl and another one to serve static content and proxy dynamic requests to apache/mod_perl, but nowadays I don't think it makes much sense unless you're using specific mod_perl features, just use Starman instead of apache/mod_perl.

Re: How to minimize memory footprint
by cavac (Prior) on Oct 24, 2011 at 13:41 UTC

    It highly depends on the complexity of the ads system.

    For example, if you only deliver some static content, something like HTTP::Server::Simple::CGI::PreFork should suffice. Just preload your content before you run() the server will give you a fast, relatively memory efficient system.

    You might also try to run memcached with enough memory to hold some of the most recent used data. Then, you do a two-way fetch: First, try memcached (with Cache::Memcached::Fast). If found, deliver. If not found then read from disk, put into memcached and deliver. Since you are not holding the data in multiple threads/instances but in a central place (the filesystem) the memory footprint is quite low. Yet, you are caching the most recently used data in RAM in a central location - this might also be important, since there's a good chance you will deliver some ads more often than others (memcached normally flushed out the oldest data and keeps the most recently used in RAM).

    Don't use '#ff0000':
    use Acme::AutoColor; my $redcolor = RED();
    All colors subject to change without notice.
      The system runs on 3 servers - back, front(apache) and images(nginx).
      I think of something like nginx does with static files.
      To load only once the script and run it from few workers, so the memory footprint will never increase.
      If it's possible ? Stable ? Production ready?
      For now the server serves about 150 request per second, the cpu is low and IO is ok... seems that only memory is a bottleneck.
      (I will read about memcache)
      Thanks.