Running a Low End VPS

A common issue when running low capacity Virtual Private Servers, is running out of memory. One of the first indications of low available memory is a sudden series of segmentation faults (aka: segfaults). Segfaulting is a common occurrence when running out of available RAM inside your VPS.

MySQL is a frequent culprit; it's possible to run MySQL on low memory, but doing so requires some basic tuning effort on your part:

  1. Add skip-bdb and skip-InnoDB if you do not need those extra database engines. Especially with InnoDB – using MyISAM-only can save you a lot of memory (and many apps work fine with MyISAM).
  2. Remove query_cache_size to disable query cache (a bit useless for low traffic sites).

In essence, the default MySQL installation on Debian/Ubuntu has a cold-start requirement of around 25MB RSS. This works well, unless you're running a tight ship with limited memory. Depending on how important MySQL is to your environment, reducing MySQL's memory demands will help lower RSS RAM requirements, and enable room for other services in your VPS.

The easiest solution is to install the stock package, immediately shutdown MySQL after installation, and then tune the existing configuration file for adequate performance. On Debian/Ubuntu, try replacing /etc/MySQL/my.cnf with my-small.cnf (located in /usr/share/doc/my-server-5.0/examples). Some important notes:

  • skip-bdb and skip-innodb are added, so you don’t get BSD DB nor InnoDB support. BSD DB support in MySQL is essentially obsolete, and many open source scripts don’t rely on the presence of InnoDB. A low end VPS is not likely to enjoy the concurrency InnoDB is offering anyway. Transaction and referential integrity? Well, one could argue that Real Programmers write their own rollback routines…although purchasing a machine with enough RAM capacity would also work ;-)
  • key_buffer is only 16K which is often insufficient. key_buffer is essentially one of the most important parameters for MyISAM tables, and I often see recommendations that you increase it to at least 1MB. The same can be said about table_cache — 4 is way too small. A WordPress page will likely touch 10 tables, and the same goes for other apps such as MediaWiki or Drupal.
  • Query cache can be useful when intending to run a busy site on a low end VPS (provided that it has a small data set, and is mostly read; blogs, news sites, etc). I recommend a query_cache_limit of 256K and a query_cache_size set to 4M.

After a few adjustment you should be able to start MySQLd at around 5-6MB RSS. You should check the runtime variables, and monitor performance…everything will work out with just a bit of tuning.

As for keeping an eye on future usage, the /proc/user_beancounters file is quite useful. Here's a VPS which recently ran out of RAM:

~$: cat /proc/user_beancounters
       uid  resource           held    maxheld    barrier      limit    failcnt
      178:  kmemsize        1279489    2741110   11055923   11377049          0
            lockedpages           0          0        256        256          0
            privvmpages       31992      32869      32768      32768         57
            shmpages              8        344      21504      21504          0
            dummy                 0          0          0          0          0
            numproc              20         27        240        240          0
            physpages          5162       5915          0 2147483647          0
            vmguarpages           0          0      16384      16384          0
            oomguarpages       5162       5915      26112 2147483647          0
            numtcpsock            3          4        360        360          0
            numflock              4          5        188        206          0
            numpty                1          1         16         16          0
            numsiginfo            0          2        256        256          0
            tcpsndbuf         26880          0    1720320    2703360          0
            tcprcvbuf         49152          0    1720320    2703360          0
            othersockbuf       4480      21760    1126080    2097152          0
            dgramrcvbuf           0       8384     262144     262144          0
            numothersock          5         10        360        360          0
            dcachesize       136144     156464    3409920    3624960          0
            numfile             439        572       9312       9312          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            10         10        128        128          0

Discussion

Enter your comment
If you can't read the letters on the image, download this .wav file to get them read to you.
 
blog/runninglowendvps.txt · Last modified: 2009/11/21 13:36 by Gregory Berkholtz