13

I need to use the minimal amount possible of RAM on a VM Server running Ubuntu, using LAMP. Is there known tips for using minimal mem? I already set the MySQL cache/childs but that isn't helping much.

2
  • 1
    I am currently running 5 word press sites and an Icecast server with one stream and an average of 5 users online on a server with only 512mb of ram. We barely see it go above 50% ram except when we get an influx of listeners. Commented May 26, 2011 at 21:25
  • 2
    Reducing mysql's memory usage is usually done by reducing buffer/cache sizes which WILL affect performance. Don't drop things so low that MySQL can't do its job. Commented May 26, 2011 at 21:26

4 Answers 4

8

What you should do, is retain Linux, Mysql and PHP, but do away with Apache. Or at least, stop running PHP in-process with Apache.

The chances are you're using the Apache prefork model with an in-process PHP module. This is very bad for memory efficiency on most workloads, because it keeps a heavy PHP process open even for HTTP connections which aren't requesting any dynamic content just now.

What you want to do instead is use another web server (for example Nginx, but Apache would work too) and run PHP as a FastCGI daemon. This is easy to set up and googling for "PHP fastcgi" returns numerous examples.

You can then have a small, fixed number of "heavy" processes running PHP (No more than a couple per core, I reckon), but still have good capacity for running real applications, because "idle" HTTP connections, such as those serving keep-alives or waiting for requests don't use up the "heavy" processes, only the lighter web server processes.

A web server which uses limited forking / few processes is probably better - such as Nginx, or Apache with a different thread model. This is incompatible with mod_php, which is why you need to run it as FastCGI instead.

Sign up to request clarification or add additional context in comments.

2 Comments

We'll study that, but I think it'll be cheaper to add more memory. Thanks!
We runned on a similar env the same application using Nginx indead of Apache, and it worked quite well (30% less mem use)
2

Make sure you turn off InnoDB in mysql, that will use about 100MB less memory

6 Comments

Make sure you know if that's a good idea, first. There are potentially huge downsides to disabling InnoDB, depending on how your application works.
Right, but from the apps he mentioned, i don't think they are using transactions.
There's quite a bit more to InnoDB than just transactions.
If you CAN turn it off, see instructions here: scorpio-jibin.blogspot.com.br/2010/01/…
not sure why this suggestion is getting any upvotes. Turn it off IF you KNOW you aren't using it (and even then, maybe you should be and don't understand the pros/cons compared to your current setup, likley MyISAM).
|
2

You can set the memory_limit in php.ini to something smaller. However if your program requests more memory than the limit then the script will crash with a fatal error.

That will only change memory usage in PHP. There may be a similar setting for MySQL in my.cnf but I don't know what it would be off-hand.

Really though the best way to reduce memory usage is to write programs that don't use a lot of memory.

Comments

2

About MySQL, Apache and others: http://library.linode.com/troubleshooting/memory-networking#sph_diagnosing-and-fixing-memory-issues

For PHP: in php.ini you can set memory_limit.

For Linux: use 32-bit versions (until you have more than 4Gb of RAM).

Don't reduce all these settings until you really need it, or it will be reason of performance degradation. Try to give enough memory to your system first.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.