Very low memory VPS Linux for Rails

 linux, vps  Comments Off on Very low memory VPS Linux for Rails
Jul 032008
 

The other day I had to set up a VPS machine at Slicehost for a client on a tight budget. I paid for 256mb VPS based on Gentoo, my distro of choice.vian34.ru

But 256MB of ram? what can you do with just 256?

Normally a default 256mb linux machine would not handle very well a set of Apache + Mysql + 1 mongrel/thin/ebb instance. due to the high memory usage of a default configuration, it will swap very often.

After much research and instinct i made it run one thin servers with mysql and nginx, without any swapping, and really fast as it can be.

If your linux start swapping often your performance will go down to the floor… Swapping is bad, specially on a XEN VPS.

The trick is to setup Mysql to use MYISAM and use Nginx instead of apache.

Here is the process list with the Resident Memory usage, after 30 days uptime and about 1,800 page views on the website.

and others, such as sshd, cron, iptables, bash, together about 5mb.

As you can see, total of memory usage of the applications on the server is about 83 MB, thus leaving the server with 170MB of ram for the linux itself and file cache.

this is what #free command tells:

Nice uh?
you can also make use of the nice tool called “vmstat”
it’s very import that ‘si’ (swap in) and ‘so’ (swap out) stays zero all the time.

i.e. running vmstat 10 times with a 4 seconds interval. (ignore the 1st line)

You can read about it more in here:

http://blog.evanweaver.com/articles/2007/04/30/top-secret-tuned-mysql-configurations-for-rails/

I forgot to add that you need to dump your database first:

mysqldump -u root –all-databases > dump.sql

then change my.cnf accordingly,

restart mysql and reload the database

mysql -u root < dump.sql

Change only the values for my.cnf as shown below, and delete all innodb related stuff

If you get problems reloading the database, stop mysql delete the contents in /var/lib/mysql/* , then run mysql-installdb and start it and reload again the sql dump file.

Actually that’s the way i most prefer..

this is an example nginx config file, located at /etc/nginx/nginx.conf

this is an example vhost file

Some linux distros have enabled by default services we dont need.

such as cupsd, apmd, acpid, mdns, samba, nfs, ftpd… etc…

Note that I set MAKEOPTS=”-J1″ , it will only use 1 gcc process at the time, and not disturb the system, (machine has 4 cores)

Also portage_niceness to 18, to make sure it will run smooth and not disturb thin and mysql.

from nice man page: “Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable).”

if you want to use mod_rails Passenger, set APACHE2_MPMS=’prefork’

note: I am positive you can throw in another thin server instance, and it will still not swap, or swap very little at all.

have fun

**************************

Wanna know what Slicehost Manager Diagnostics says about my VPS ?

analytical critical thinking

 Uncategorized  Comments Off on ruby-mysql now Ruby 1.9 compatible
Mar 072008
 

Tommy has just released an new mysql-ruby package.Окраска стен

Actually 2 of them:

mysql-ruby-2.7.5 and mysql-ruby-2.8pre2

They are Ruby 1.9 compatible
Requirements

* MySQL 5.0.51a
* Ruby 1.8.6, 1.9.0

here is the link http://tmtm.org/en/mysql/ruby/

Great Job

Switch to our mobile site