0

I have successfully configured nginx to serve a WordPress blog (at example.com/blog) alongside a Rails app. My stack is as follows:

Ubuntu 10.04, ngninx, unicorn (1 worker process for the Rails app), spawn-fcgi (for PHP and WordPress), and PostgreSQL.

My question is simple. How much memory should the above require? Currently I have 256mb, and it's completely dedicated to this app. My postgres process has already crashed once, so I'm afraid I need more. Is there a way for me to optimize this? Any thoughts?

I should mention that I'm a developer and completely new to server administration. This is my first attempt at deploying a Rails app to an unmanaged VPS.

EDIT: For what it's worth, here are some current statistics.

$ free -m
             total       used       free     shared    buffers     cached
Mem:           256        168         87          0          0          0
$ ps aux # => just the highlights
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
deployer  2014  0.0  6.4  21676 16880 ?        Sl   Apr29   0:00 unicorn master -D -c /home/deployer/apps/dailyshimmer_v
deployer  2017  0.0 29.6  86112 77856 ?        Sl   Apr29   0:12 unicorn worker[0] -D -c /home/deployer/apps/dailyshimme
postgres  5539  0.0  2.5  43304  6624 ?        S    03:47   0:00 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgr
postgres  5541  0.0  0.8  43304  2116 ?        Ss   03:47   0:05 postgres: writer process                              
postgres  5542  0.0  0.4  43304  1264 ?        Ss   03:47   0:04 postgres: wal writer process                          
postgres  5543  0.0  0.9  44136  2372 ?        Ss   03:47   0:01 postgres: autovacuum launcher process                 
postgres  5544  0.0  0.5  13900  1352 ?        Ss   03:47   0:01 postgres: stats collector process                     
root     12074  0.0  0.4   8724  1096 ?        Ss   Apr29   0:00 nginx: master process /usr/sbin/nginx
www-data 12075  0.0  0.8   9224  2240 ?        S    Apr29   0:00 nginx: worker process
root     30334  0.3  8.3  43600 21812 ?        Ss   00:52   1:08 /usr/bin/php-cgi

2 Answers 2

2

I don't think it's unreasonable to scale up to 512mb. The app should run fine on 256mb, but multiple concurrent requests are going to hurt you, and you also need to leave some space for your database and everything else on the system. If postgres has crashed due to lack of RAM (you didn't say that was the issue) you should definitely scale up RAM.

There is a lot you can do to optimize. One thing is to attack both your Rails app and your Wordpress setup to maximize browser-side caching and reduce the number of requests your apps get. ("The fastest HTTP request is the one which doesn't get made.")

1
  • Thanks for the reply. I would love to keep the app at 256mb (to save money), but I also want it to run smoothly. I guess I assumed it crashed because of the lack of memory - is there something else that could have caused it? It's worth mentioning both the postgres and the fcgi process stopped all of a sudden.
    – Feech
    Apr 30, 2012 at 1:47
2

Running a database server on 256MB of RAM is unheard of in this day and age. I would not run a Linux/nginx/Postgres/PHP stack on any less than 1GB of RAM. To top it off, you want to run a Ruby application, and Ruby is not known for its overall economy with memory.

Having less RAM is a false economy because you'll waste more time waiting for your VPS to respond. It might technically launch all of those processes, but they'll run terribly. Less RAM means that your Postgres instance can't cache tables into RAM, and those cache misses will manifest as a near-unusable application.

Is worrying about all of these things really worth the pittance you're saving?

2
  • Thanks for the input. 1GB of ram wouldn't be overkill for one app? I might end up buying a Linode 512 for $20/mo, but I'm not sure about spending $40/mo on a 1024 yet. I agree though, worrying isn't worth it.
    – Feech
    Apr 30, 2012 at 14:28
  • It's definitely not overkill. Once you start throwing in plugins and needing to cache PHP, you'll be grateful you have the RAM to keep performance high. Apr 30, 2012 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .