Reducing the load on a small VPS by 80% in 5 minutes
turnkeylinux.org
turnkeylinux.org
Use the right tools for the job I think. If you've got a vps with 256-512mb do not run heavy process forking applications when something else has been written exactly for this situation. I'm a big believer in apache, I think its great with mpm worker or event but prefork is really inefficient and in my opinion a legacy mpm. Unless you truly need apache (in our case custom written modules) then switch to lighttpd or nginx. These are proven to be extremely fast, highly configurable and low in memory usage.
I havent found an alternative to spamassassin but that thing consumes far too much memory and cpu than I like. If you find something else, use it. Its been around for a lifetime and someone needs to come out with a new solution.
If you have free or cached memory and think the kernel is swapping out your process then set a value between 0 and 100 in /proc/sys/vm/swappiness. 100 more likely to swap.
Here is another thing, look at whats running. The OS brings up alot of unneeded processes, stuff that you'll probably never use. Do ps aux and check it out. Or top and reorder by mem usage.
Nginx, Lighttpd, Cherokee, Zeus, LiteSpeed, etc. All use far fewer resources.
But litespeed can get expensive for large installs so I don't blame people looking for free/opensource alternatives. All depends how much time you have and if you are building from scratch vs. upgrading an existing Apache install.
The great thing is, we have so MANY choices today compared to just 5-6 years ago, it's awesome.
But litespeed will certainly double the capacity of any Apache install, no exaggeration, and it's ddos resistance is second to none. I just wish it wasn't so expensive.
I've often found myself needing to patch the software I use to get it to work just right. Even when a proprietary software vendor gives you source code the build system often sucks and the code is not hacker friendly.
Also the licensing would restrict you from doing all sorts of things you wouldn't have to think twice about with an open source web server (e.g., auto-scaling in a cloud configuration)
Unless you need the backwards compatibility with Apache don't use LiteSpeed. There are excellent open source alternatives which are just as good and perhaps superior. Minus the Apache compatibility.
http://agentzh.org/misc/slides/nginx-conf-scripting/nginx-co... disagrees with your assessment of the nginx configuration system.
skip-bdb
skip-innodb
# default is 8M
key_buffer_size=4MFor example I have a number of FastCGI PHP processes running, each consuming up to 20MB. I tuned it so that if each one takes exactly 20MB (more or less max memory limit I set), then I still have a sliver of RAM left. That way there is no cost of starting/stopping these processes and there is maximum resource utilization.
For environments using Passenger, there is a great tool available for analyzing this: passenger-memory-stats. By examining the source code of this tool[2], we can see that it is examining the contents of `/proc/#{pid}/smaps' where pid is a collection of Apache process IDs that is iterated through. Writing a bash/awk script to accomplish the same should be pretty straight forward. But back to the topic of reducing memory usage and pre-forking.
In our deployments, an Apache process uses 0.5 MB of physical memory, which puts the reduction of Apache processes in to perspective. At this level, your Apache server would have to be grossly misconfigured for this to have a significant impact. Also, the purpose of spare processes is to disguise the overhead required to create new processes. The only reason you'd use this functionality is when you have a load that varies. That is to say, you should set your MaxClients configuration so that you don't spawn processes that your VPS can't support.
Any benefit of reducing pre-fork processes is lost once load increases to the point that you need those processes to serve requests. This cannot save you from an under-provisioned VPS instance. A better solution is to cap the maximum number of worker processes to limit swap usage (called thrashing). You'll still encounter a performance ceiling if you've under provisioned your VPS.
The same applies for any service that uses pre-forking. There is no substitute for understanding your service load requirements. You have to answer two questions: How many req/sec are you serving, and how many req/sec can each process/thread serve (depending upon your service worker model). This is accomplished using benchmarking tools.
While you should definitely make sure you're running an appropriate number of workers, you'll get more benefits from reducing the amount of memory used for each process. When I started, our Apache processes were around 7 MB of private dirty RSS usage each. The processes were large because there were all kinds of Apache modules loaded that weren't in use. PHP, mod_perl, etc. Each of these contribute to the process bottom line memory usage.
Let's look at memory usage as s * n where 's' is the size of each process and 'n' is the number of processes. Our variable 's' is typically a small number (say, 0.5 to 10 MB), while 'n' is typically a whole order of magnitude (or two) greater. In our case, 'n' is 150. Reducing 's' from 7 MB to 0.5 MB saved me 975 MB of real memory! If I had ignored my process size and only reduced the number of workers by 20% (which would still degrade performance at peak loads), I would only save 210 MB. The hit in performance cannot be understated. Running out of Apache workers is NOT good for performance.
In summary, the article offers good advice only in the fact that you should know and understand what your service requirements are. I would disagree that you should review your process/thread usage, and call it a day. There are many other 'low hanging fruit' items to reach out and grab.
1 - http://www.google.com/search?q=linux+top+vs+private+dirty+rs...
2 - http://github.com/FooBarWidget/passenger/blob/master/bin/pas...
Spamassassin might do this differently though and I suspect child processes are more likely to use all the reported memory.
There are far better options like greylisting or just adding spam blacklist services (spamhouse, spamcop) to the "reject" configuration of the mail server.
Also, SA leverages blacklist services (and other techniques, it's very configurable) and is easier to integrate into your mail server.
Basically I don't know why anyone nowadays would use spamassassin (I've used it in the past) when there's graylisting and blacklist servers that work wonderfully with low overhead.
I've started a web server poll: http://news.ycombinator.com/item?id=1414076