Apache running in 48 MB of RAM
This is not an example of how to run Apache in an efficient manner, but it is a small demonstration that things are not always as they seem and that the tool can be crafted for the job at hand.
phpinfo:
free -m/ps (live):
I'm tempted to install phpBB and see if it will run. Now that I've posted this, someone will probably OOM it, so have fun. :)
8 Replies
If you wouldn't mind, could you give some advice as to how you configured that system to minimize memory usage?
Anyway… apache isn't that bad on memory, especially with worker/fastcgi instead of prefork/mod_* . And inb4 "if you do fastcgi already, there's no reason for you to stick to apache": there's also no need to switch. Not to mention that apache is the most familiar and most configurable one out there.
PS. Jed, is a Li512 enough for minecraft server, or does it still try to alloc over a gigabyte at start?
@jed:
free -m/ps (live):
http://minecraft.jedsmith.org/memory.php
The Monte Carlo hit counter is a nice touch. I wound up reloading the page a bunch of times to watch it change.
Sure, you could spend hours figuring out and tweaking Apache, or you could spend five minutes installing lighttpd or nginx and be done with it. I also favour fastcgi, although that can also be done with Apache. But again, it's a lot easier to set up fastcgi with lighttpd than apache since it's the default way of handling PHP in lighttpd.
Setting up perl with lighttpd however, is much less fun. At least with fastcgi.
EDIT: Also, Minecraft rocks. Too bad the author chose Amazon over Linode
@jed:
I edited a Linode on my account that I use for Minecraft to only have 48 MB of RAM available to it, then installed Ubuntu 10.10, prefork Apache2, and PHP 5.
It's worth pointing out a few things this demo doesn't have, unlike many of the bulkier PHP deployments: no CMS/framework, no images/CSS/JavaScript objects, and no time-consuming SQL queries. A framework adds bulk, objects multiply concurrent requests, and SQL queries lengthen the time per request. Since prefork requires a fully-stocked forked Apache process for each concurrent request, whether it requires PHP or not. That's where nginx and lighttpd come in.
How happy is PHP with mpm_worker/multithreading these days? That would be really, really useful.
@Erasmus Darwin:
The Monte Carlo hit counter is a nice touch. I wound up reloading the page a bunch of times to watch it change.
It looks really familiar.
I'm using worker with modfastcgi (NOT modfcgid!) and I'm happy about everything except one little detail that may be a deal-breaker for you: fastcgi's process manager cuts the FCGI socket and SIGTERMs the PHP tree (and anything else you'd have hanging off FCGI) when you SIGUSR1 apache for a graceful config reload. In result, every connection that was in the middle of a PHP-processed request receives HTTP 500.
I'm not running anythig mission-critical, so setting up logrotate to the time of lowest traffic and warning users when reloading apache's config during the day works for me.
@hoopycat:
@Erasmus Darwin:The Monte Carlo hit counter is a nice touch. I wound up reloading the page a bunch of times to watch it change.
It looks really familiar.
It should, it's yours (I'm filegetcontents()ing the URL).
@Guspaz:
Sure, you could spend hours figuring out and tweaking Apache, or you could spend five minutes installing lighttpd or nginx and be done with it.
The configuration here took about 60 seconds, of just turning all the prefork values down to near-minimum.
@rsk:
PS. Jed, is a Li512 enough for minecraft server, or does it still try to alloc over a gigabyte at start?
The node was 1 GB before, and it makes me nervous to run Minecraft on it. SMP Alpha is buggy enough anyway that it isn't worth it to me.
@akerl:
If you wouldn't mind, could you give some advice as to how you configured that system to minimize memory usage?
Surprisingly, I just turned the prefork values down to almost the bare minimum, and disabled all but four modules (authz_host, dir, mime, and php5).
Clearly it's not going to be very performant, but it does work. I even stopped atd, cron, and some other services (as you can see in the ps output).
@hoopycat:
It's worth pointing out a few things this demo doesn't have, unlike many of the bulkier PHP deployments: no CMS/framework, no images/CSS/JavaScript objects, and no time-consuming SQL queries. A framework adds bulk, objects multiply concurrent requests, and SQL queries lengthen the time per request.
This.
@Guspaz:
Sure, you could spend hours figuring out and tweaking Apache, or you could spend five minutes installing lighttpd or nginx and be done with it.
For an awfully large percentage of the cases discussed in these forums, simply dropping MaxClients (or equivalent setting depending on worker model) is all it would take to get the lion's share of the improvement with very minimal time and effort.
– David