Making the most out of a 64MB VPS
About 2 months ago I got myself a Virtual Private Server(VPS) from http://www.vpsvillage.com. I am paying $5 a month for a Xen virtual machine with 64MB of RAM and a 4GB hard disk. I have lots of plans for my VPS. The most essential is hosting my website (basically this blog plus a small rails app). I immediately installed a LAMP environment and had my blog up and running in no time.
Now I have a very small number of hits per day… So small that I am embarrassed to post that number here:). Suffice to say that it would be better to calculate per week or month 🙂 Anyhow my site site kept dieing on me. The Out of Memory thread (OOM) kept killing off processes on my server.
Rather that tune apache I decided to install lighttpd and try and tune the rest of my system. So I did a fresh install of 64-bit ubuntu (actually I now feel that the 64-bit part was a mistake but I am not sure enough to go through the whole install process again). I will attempt to describe how I went through the process of tuning my 64MB VPS.
Tuning Tools
I installed munin as it produces lovely graphs. The graphing process it quite heavy so to lower its impact I removed all unnecessary plugins (I kept: cpu, load, memory and swap only) and I also modified the cron script so that the graphs and html files are updated every 15 minutes (munin updates every 5 minutes)
I am now able to look at nice graphs of my memory usage
you can see munin in progress here
Tune Linux
Next thing I did was to try and tune the virtual memory subsystem (ie /proc/sys/vm/*
). I fist tried to lower the swappiness value but that did not have the result I expected! You see I thought that a lower swappiness value would decrease the systems tendency to swap caches to disk. It in fact decreases the tendency to swap anything to disk. I was getting OOM with swap only a quarter full.
What I did at the end was:
- leave swappiness at the default value of 60
- set vfs_cache_pressure to 200
- set max_map_count to 1000
No doubt further understanding of the VM subsystem would allow more efficient tuning, but that will have to wait for another day.
Tune Lighttpd
With the small load I have and the small memory footprint of lighty (less than 1MB), I can’t see much to be done here! I have setup php o run as a fast-cgi process. I have set max-procs to 1 in lighty with PHP_FCGI_CHILDREN=1. This means we will have 2 php-cgi processes, one is the parent monitoring process (PP) and the other will actually serve requests (SP). I might increase PHP_FCGI_CHILDREN to 2 in the future.
Tune php
I wanted to see what I could do to decrease the memory footprint for my php-cgi processes so I hit my site with:
ab -n 50 http://azein.com/
and fired up top (using M to sort by memory usage) and got
2163 www-data 16 0 77396 13m 3100 S 0.0 21.6 0:08.36 php-cgi
2162 www-data 23 0 69212 6132 3668 S 0.0 9.4 0:00.00 php-cgi
I then edited my php.ini file and modified the following values:
memory_limit = 16M
register_long_arrays = Off
;engine = On
I also commented out the loading of the mysqli, pdo and pdo_mysql modules as I don’t use them.
I tried again with ab -n 50 http://azein.com/
and got:
2278 www-data 16 0 71096 12m 3016 S 11.3 20.2 0:09.36 php-cgi
2277 www-data 24 0 62660 3596 3528 S 0.0 5.5 0:00.00 php-cgi
so we have a small decrease in memory foot print.
Tune MySQL
1st thing to do before you even start to tune your parameters is to skip-innodb
this by itself is supposed to decrease the memory foot print by 100MB.
The 1st parameter I will tune is the key_buffer
. This describes the amount of memory used to cache the tables keys and indexes. The sum of my *.MYI files are about 80K so I will set the key_buffer
size to 512KB with lots of room for expansion.
The 2nd set of parameters are the threads and concurrency group, now I plan to have no more than 2 php-cgi threads running at any time so it make no sense to have more than 2 mysqld threads running for now. I also set the max connections to 10 as I do not expect any more than that.
max_connections = 20
thread_concurrency = 2
The 3rd set of parameters are the query cache configuration group. I do not have many queries that I think need to be cached. I suppose the front page of my blog (about 10 posts) is all that will benefit from this.
query_cache_limit = 64K
query_cache_size = 512K
mysqld now consumes just under 7MB but I will take a look at my hit/miss stats in a few days to how the query cache parameters are doing.
Last thing I did was turn off binary logging and I do not plan to use it.
Final Comments
No mater what I did I couldn’t get my rails app running without the system coming to a halt! The rails app has a memory footprint of 30MB and I don’t have the energy to see if it possible to bring that down and what the minimal memory footprint of a rails app is!
I could upgrade my VPS to 128MB RAM, but I think that 64M should be sufficient and I will continue trying to make the most out of it.
October 7th, 2007 at 8:47 pm
You are getting at least 12 hits per day from my aggregator 😉
Rails + 64M ? I don’t think so. Point is you are already using memory for postfix, apache || lighttpd and mysql not to mention php.
For MySQL and since you are getting low traffic, I’d decrease (Yes) key_buffer_select. You can afford to swap a bit and you can afford more IO than xaching things in memory.
October 7th, 2007 at 8:49 pm
Of course I donno how much resources are being used by wp but I was running drupal on 64M long ago.
October 8th, 2007 at 5:59 pm
Mohammed Sameer: I will try that!
Thanks
February 13th, 2008 at 1:39 am
[…] Zein: Making the most out of a 64MB VPS — how Ahmed tuned his 64MB Xen VPS from VPS Village to run Lighttpd, PHP/FastCGI and MySQL. He was also trying to get a Ruby on Rails app running but OOM seems inevitable. Great article on getting PHP applications like WordPress running on a minimal VPS. […]
April 12th, 2008 at 2:57 pm
[…] vps village上的vps,最便宜的是64MB内å˜ï¼Œ4G空间,一个月。但是那网站,基本没什么内容。自称是GrokThis.net的一个division。但我email过GrokThis.net询问两者关系,也没有结果。看上去åƒéª—å的。但是这ä½ä¹Ÿç”¨äº†ä¸€æ®µæ—¶é—´äº†ï¼Œå¥½åƒè¿˜ä¸é”™ã€‚(è¯è¯´ï¼Œä»–那时è´ä¹°æ‰ï¼Œæ€Žä¹ˆhostä¸è·Œå涨呢?) […]
April 16th, 2008 at 4:05 pm
Thanks for your info.
June 8th, 2008 at 5:29 am
Interesting read, VPS’s are great!
June 9th, 2008 at 9:57 am
Interesting read, I currently have a 294Mb Ram VPS, after reading this I think I can easily cut back to something cheaper like around 128Mb ram anyway.
June 16th, 2008 at 7:45 am
Hello, are you still using vps from vpsvillage.com? How things going? Did you get rail app running? I am considering their 64M plan, but they have increased the price and requires quarterly payment now. I’ll be appreciated if you can post more reviews on their product and service here. Have a nice day.
June 17th, 2008 at 7:18 pm
Wow 64megs huh nice read. Think its time for an upgrade=) Do what I did I grabbed a full managed Server from Server Intellect then I had them install MS virtual server software then resold 6vps out to my friends to cover the cost of the Server. I got 512 in each vps=)
June 21st, 2008 at 8:55 am
mattw:
My experience with vpsvillage has been excellent. I may a year in advance anyway to get my extra free month. Their service just works. I have had no need to communicate with them for any issues.
June 24th, 2008 at 8:23 am
Thanks for your reply and good article. Did you ever run unixbench-wht (http://www.webhostingtalk.com/showthread.php?s=&threadid=308055) on your vps? I am curious about the benchmark score on such a small system.
November 9th, 2008 at 1:38 am
Hello, are you with vpsvillage since 2007/10/06? Is good comapny? did you have problems?
November 20th, 2008 at 11:48 am
Magas:
Yep! I have had no problem with them at all.
November 23rd, 2008 at 8:11 am
Hello again, i got a vps but i have a problem..
This is the commands i executed:
apt-get update
apt-get-upgrade
apt-get install mysql-server mysql-client
I got Memory Allocate Problem but after i changed the my.cnf, restarted the server and all was fine.. Am i ok or will i have problems?
December 1st, 2008 at 2:11 pm
Magas:
I would say that it is difficult to do a lot with 64MB. I would monitor the VPS for a week or so. use “dmesg | tail” to make sure you are not getting any OOM issues. If not then you should be OK.
January 13th, 2009 at 4:51 am
Try call:
ulimit -s 128
before your Rails app execution. It will reduce stack size per process from 8MB to 128 KB that is sufficient for typical apps (multiuply this by number of threads). Your virtual memory usage will drop instantly (checked with TurboGears Python apps).
February 15th, 2009 at 4:16 am
[…] Оригинал поÑта находитÑÑ Ñ‚ÑƒÑ‚: http://www.azein.com/blog/2007/10/06/stretching-64mb-as-much-as-you-can/ […]
March 29th, 2009 at 8:08 am
Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language 😉
See you!
Your, Raiul Baztepo
August 8th, 2009 at 7:29 am
Wow, 64MB! Have you upgraded in the meantime? I cannot get my WordPress site to work smoothly on a 128MB VPS and that is with WordPress 2.8.3… I’m still considering whether to upgrade or to switch back to shared hosting.
August 31st, 2009 at 11:51 pm
I am still using the 64MB VPS. I am happy with it and am not planning to change any time soon 🙂
October 3rd, 2009 at 2:53 am
Привет. ПодÑкажите, как перевеÑти блог Ñ Ð´Ð°Ñ€Ð¾Ð²Ð¾Ð³Ð¾ хоÑтинга, вот мой блог разное
Вроде как wordpress обÑзан Ñ Ð»ÐµÐ³ÐºÐ¾Ñтью перемещатьÑÑ Ð½Ð° Ñвежую площадку, Ñ…Ð¾Ñ‚Ñ Ñƒ Ð¼ÐµÐ½Ñ Ð²Ñе Ð²Ñ€ÐµÐ¼Ñ Ð¾ÑˆÐ¸Ð±ÐºÐ¸ в базе данных. Я поÑмотрел там, Ñ…Ð¾Ñ‚Ñ Ð² php ничего не знаю вообще и привлекать Ñторонних программиÑтов то ведь не хочетÑÑ. Может подÑкажите, как безболезненно перенеÑти блог?
January 9th, 2010 at 11:06 am
[…] Zein: Making the most out of a 64MB VPS — how Ahmed tuned his 64MB Xen VPS from VPS Village to run Lighttpd, PHP/FastCGI and MySQL. He was also trying to get a Ruby on Rails app running but OOM seems inevitable. Great article on getting PHP applications like WordPress running on a minimal VPS. […]