I have a rails app using renv/Phusion Passenger/nginx on Ubuntu. My server has a small memory size, and the rails app is rarely invoked, so I need to find a memory optimal configuration on Phusion passenger/nginx.
Setup nginx.conf
I tried to minimize the memory usage, so I keep only 1 pool, and tried to minimize the idle time. I got information from this site: https://www.phusionpassenger.com/library/config/nginx/reference/#passenger_pool_idle_time
user www-data;
worker_processes 1;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
...
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
passenger_max_pool_size 1;
passenger_pool_idle_time 1;
passenger_root /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/passenger-5.0.21;
passenger_ruby /home/ubuntu/.rbenv/shims/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Setup rails.conf
I have this configuration to rails.example.com
is connected to a rails app.
server {
listen 80;
server_name rails.example.com;
passenger_enabled on;
passenger_app_env development;
root /home/ubuntu/webapp/rails/passenger-ruby-rails-demo/public;
}
Checking the memory usage with htop
, I have this map.
However, the information shown is not exactly the same as the one from sudo passenger-memory-status
command.
The htop
report has four Passenger RubuApps (with 3317, 3319, 3314, 3320 pids), but passenger-memory-status
only shows 3314 pid. The same is true with other processes (core, watchdog, ust-router). I think htop
shows the correct memory usage.
What makes the differences in memory usage information? I'm also curious about
- How to minimize the memory usage of Phusion passenger with nginx?
- Is there a way to kill passenger processes after a certain amount of time when there is no rails app invocation?
- Other than Phusion passenger, what might be the way to use least amount of memory?
EDIT
Modifying the setup of htop
to show in tree format and show threads in different color results in showing one process.
EDIT2
Passenger AppPreloader consumes the memory as much as RubyApp does.
After killing the AppPreloader, the memory consumption is smaller, and the app seems to be working fine.
I'm not sure if AppPreloader is absolutely necessary (for optimal memory usage) and is there an option not to use it.