I idle in #slicehost, an IRC channel for my VPS provider, and see people come in all day long complaining about how slow their app is running on Slicehost compared to shared hosting. Nearly every single time the user installed Ubuntu (not that there is anything wrong with that; it’s what I use) and are using apache + mysql. Most of the time they are running a 256MB slice but on occasion you’ll see someone come in with a 256MB slice and upgrade to a 2048MB slice because they think it will help. It won’t; they are wasting money. They need to learn that there is more to setting up a VPS than:
sudo aptitude install apache2
Most of the time it isn’t that they have terrible database indexing. It isn’t even that they aren’t caching anything. The problem is that they keep the Ubuntu apache default settings which spawns over 100 server processes. Each one takes up at least 15MB and brings the server down to it’s knees. As soon as your server starts swapping it’s performance is going to take a nose dive. So let’s reduce the number of processes apache spawns:
sudoedit /etc/apache2/apache2.conf
And search for this section and make these changes (assuming you are using the default prefork module):
<IfModule mpm_prefork_module> StartServers 2 MinSpareServers 2 MaxSpareServers 4 MaxClients 4 MaxRequestsPerChild 250 </IfModule>
That is a good place to start; everyone will have to tweak these as necessary but for a 256MB slice it should work well. It tells apache to start with 2 processes, allow between 2 and 4 processes to idle, run a maximum of 4 processes, and to restart a process after it serves 250 requests (which is like a get out of jail free card if you are leaking memory). Note that this does not mean that you can only handle 4 users at a time. It means you can handle 4 requests at a time and any other requests are queued up. Watch your memory usage (using top or free) and tweak these numbers as necessary.
There are other easy fixes that I won’t get into:
- Use a separate media server (S3 maybe) and turn
KeepAliveoff for your dynamic server. - Use memcached to cache anything and everything.
- Reorganize your database. In mysql try to avoid using blobs if possible. If you need them then move them off to their own table because mysql cannot cache columns with variable length. This was RSSmeme’s problem; a database reorganization that took 5 minutes resulted in complex queries taking .01 sec instead of 5 sec.
- Fine tune your database. Depending on your app you might consider modifying
query_cache_size,sort_buffer_size,key_buffer,tmp_table_size, andtable_cache. Removing innodb support (if you don’t need it) will save you an easy 10MB.
And please take everything you read on the internet about fine tuning your VPS with a grain of salt; including this. I do not consider myself an expert at this; I’m far from it. I could be very wrong and this could be terrible for your needs. The point is that you need to put just a little bit of effort into setting up VPS. Good luck!

Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks