HOWTO: Speed up initial load times using Passenger
Added by Brian Smith about 12 years ago
Environment:
BlueOnyx Web Panel
CentOS v5.x
Redmine 2.0.3
Ruby 1.8.7
Gems 1.3.7
Rails 3.2.6
Background:
I am the lone developer on a small project. When I visit my internal Redmine site, the initial load time is 6-8 seconds. If I do not visit for it a while, it is once again 6-8 seconds to load. After it loaded, speed was wonderful.
Issue:
FCGID, FastCGI, Passenger all would time out after a period of inactivity. When attempting to get it to auto start on Apache restart, it never would.
Solution:
I removed FastCGI, FCGID from my Apache before I ran through this.
Install Passenger: http://www.modrails.com/install.html
When completed, it will tell you to update your Apache configuration. For example, my install said the following;
"Add the following to your Apache configuration"
cat /etc/httpd/conf.d/mod_passenger.conf
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.13/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.13
PassengerRuby /usr/bin/ruby
I am using a hosting GUI called BlueOnyx, as a result. I have virtual sites using a mix of name based, and IP based virtual sites. To finish setting up Passenger, you must update your site settings. If using Apache ONLY for your Redmine, most likely, you can put it any where. Since I have virtual sites, I had to put it into my virtual site container.
PassengerMinInstances 2
PassengerPreStart http://redmine.domain.tld/
The Minimum Instance configuration is required to ensure that Passenger is always waiting for a connection. This avoids the 6-8 second start time after a period of inactivity.
The Pre Start configuration is how Passenger starts my virtual site when Apache starts. No more annoying wait time.
After this was added, Apache was restart, but my Redmin application never started. Time to do some more digging.
By default, PassengerPreStart contacts your Apache using "127.0.0.1". The issue is that I am using IP based virtual sites. As a result, Apache pretty much ignore my request.
bart.domain.tld 127.0.0.1 - - [03/Jul/2012:19:59:15 0400] "HEAD / HTTP/1.1" 200 - "" "-"
After digging around, this is how Passenger works, which won't work in my environment. Time to hack their application slightly.
- NOTE * If yours doesn't work, you will have to do this. The problem is there seems to be a mix of feelings of you should do this or not. In my environment, I have no issues because I do not have a cluster and my DNS resolution works properly.
On a 64bit system, there are two files you have to modify;
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.13/helper-scripts/prespawn
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.13/helper-scripts/prespawn
If you are using a 32bit system, then you probably will have just the first file. Also, please note, I am using 3.0.13, so your version my be different.
Edit the file, and search for;
TCPSocket.new('127.0.0.1', request_port)
Change to:
TCPSocket.new(request_host, request_port)
If your second parameter does NOT say "request_port", do not use this. They apparently have changed the variables over time. Scroll through the file, you should be able to determine which variable to use. If you cannot, please do not modify this file.
After making that change, restart your Apache.
I spent some time Googling for other settings for Passenger, since I have never used it or Rails, and came up with the various settings. Please note, just because they work for me, does not mean they will work for you. You should Google them, and see if they work for you.
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"
PassengerMaxPoolSize 5
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 900
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
PassengerMinInstances 2
PassengerPreStart http://redmine.domain.tld/
RailsAppSpawnerIdleTime 0
RailsFrameworkSpawnerIdleTime 0
Replies (4)
RE: HOWTO: Speed up initial load times using Passenger
-
Added by Jan Niggemann (redmine.org team member) about 12 years ago
Which version of mod_passenger do you use?
RE: HOWTO: Speed up initial load times using Passenger
-
Added by Jan Niggemann (redmine.org team member) about 12 years ago
Seems like mod_passenger 2.2.11 doesn't support
"PassengerMinInstances" and "PassengerPreStart"...
But I'm so happy that redmine is running, I don't dare replacing Debians mod_passenger with the (newer) gem version. Not that I knew how to do that in the first place...
RE: HOWTO: Speed up initial load times using Passenger
-
Added by Brian Smith about 12 years ago
Try using;
passenger_pre_start
passenger_min_instances
There are some changes between yours; 2.2.11 and mine; 3.0.13.
That is part of what I was trying to write about if you have to edit your "prespawn" script. You may need to use a slightly different variable name there as well.
RE: HOWTO: Speed up initial load times using Passenger
-
Added by Jan Niggemann (redmine.org team member) about 12 years ago
Brian Smith wrote:
Try using;
passenger_pre_start
passenger_min_instances
Nope:
Invalid command 'passenger_min_instances', perhaps misspelled or defined by a module not included in the server configuration
IMHO the Debian stable mod_passenger 2.2.11 I'm using just doesn't implement this...