5

I'm currently facing a problem with Passenger (4.0.18) in combination with a simple Rails 4.0.0 application. Problem is, that after starting apache, the first request is extremely slow ( usually 30.x seconds). The following requests are really fast but if the app is idle for 20+ seconds, the same happens again.

Now, this problem in general has already been discussed here several times, and of course I already tweaked the apache config:

 PassengerSpawnMethod smart
 PassengerPoolIdleTime 1000
 RailsAppSpawnerIdleTime 0
 PassengerMaxRequests 1000
 PassengerMaxPreloaderIdleTime 0

But this did not help at all. If I check passenger-status it tells me this:

 Version : 4.0.18
 Date    : 2014-01-31 13:06:59 +0100
 Instance: 20601
 ----------- General information -----------
 Max pool size : 6
 Processes     : 1
 Requests in top-level queue : 0

Funny thing is, that when I do a 'watch' on passenger-status while doing a request, nothing really changes here. (Especially not the Requests line).

I already fiddled around with tcpdump, all requests arive in time, so there's no network delay visible. I also enabled apache extended logging ( with added request times ) - this is quite interesting, let's say a normal request takes around 200msec, then one of these slow requests takes exactly 30.2 seconds.

Any idea what this could cause?

Apache is a 2.2.15. (redhat version, with backported security patches...:) )

Thanks in advance, Björn

McSlow
  • 69
  • 6

2 Answers2

2

Use PassengerPreStart: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPreStart. That documentation section also explains why you experience the behavior that you observe.

Hongli
  • 18,682
  • 15
  • 79
  • 107
  • 1
    Hi, thanks for your help - I already tried that, unfortunately without success. What I was wondering is, that this should have helped at least for the first request ( by "faking" a first request) but it shouldn't have any effect on subsequent request after idling for a while ( where I'm also facing problems ) - at least not with PreloaderIdleTime and PoolIdletime set to 0 and 1000. ( So all processes should survive for a time). Is there a point where I can clearly see when passenger processes are removed due to some timeout or things like that? – McSlow Jan 31 '14 at 13:32
  • Try adding the PassengerMinInstances directive. Combined with PassengerPreStart, it should solve your issues. Reference: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerMinInstances – niiru Jan 31 '14 at 15:43
  • Hi thanks for all your help. I finally found out what the problem was. First: Both directives were needed to remove the initial delay. And this works fine. Problem for the subsequent delays was a completely different story: The apache httpd has a "GetAccess" Module installed, which is some very proprietary central entitlement software, there, one of the backend servers made some trouble and no one noticed it. Finally found it out by increasing and checking the passenger log ( the request arrived at the apache access log in time but was handled by passenger 30 seconds later....) – McSlow Feb 03 '14 at 12:30
-1

An easy and secure way to make sure that your server is up and ready for processing request is to make a crone job to curl the website every n minutes (which in my case n = 3).

my crone script is:

 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /var/www/example.com && curl -i https://www.example.com/ >> log/curl-www.example.com.log 2>&1'

you can validate the crone task here

dariush
  • 3,191
  • 3
  • 24
  • 43