Understanding Apache + Passenger directives - how do they work together?

380 views
Skip to first unread message

Ram

unread,
Jun 2, 2010, 3:28:15 AM6/2/10
to Phusion Passenger Discussions
Hi,

Ive got Passenger 2.0.6 and Apache 2 setup for a Rails app staging
server running standard Ruby (not REE). Im trying to optimize the
setup using tools like ab (Apache Bench) to gather metrics and
passenger-memory-stats to study the memory usage (since I hear 'top'
is extremely misleading - http://ahref.in/e4407).

Now although I went through the Passenger Architecture document, I
dont understand how Apache and Passenger work together in handling
resources+requests. This confusion came about primarily because of one
passenger-memory-stats output.

Apache processes - ### Processes: 11 ### Total private dirty RSS: 2.58
MB
Passenger processes - ## Processes: 10 ### Total private dirty RSS:
268.52 MB

Now I thought that since the parent mod_passenger sits inside the
parent Apache process and inside every other worker process, the total
private dirty values should match. But they're nowhere even close!
Where did I go wrong there?

I think Im missing how the directives for both these servers affect
each other.

For Apache, im using the default prefork_mpm with the following
settings

StartServers - 5
MinSpareServers - 5
MaxSpareServers - 10
MaxClients - 150
MaxRequestsPerChild - 0

I want to understand how these map to/affect Passenger's own
directives listed below

PassengerMaxPoolSize
PassengerMaxInstancesPerApp
PassengerPoolIdleTime
PassengerMaxRequests
PassengerStatThrottleRate

I havent set values for the above directives currently - they are at
their default values.

Hope you guys can help me understand this stuff.

Thanks!



Hongli Lai

unread,
Jun 3, 2010, 5:52:23 AM6/3/10
to phusion-...@googlegroups.com
On Wed, Jun 2, 2010 at 9:28 AM, Ram <yourstru...@gmail.com> wrote:
> Hi,
>
> Ive got Passenger 2.0.6 and Apache 2 setup for a Rails app staging
> server running standard Ruby (not REE). Im trying to optimize the
> setup using tools like ab (Apache Bench) to gather metrics and
> passenger-memory-stats to study the memory usage (since I hear 'top'
> is extremely misleading - http://ahref.in/e4407).
>
> Now although I went through the Passenger Architecture document, I
> dont understand how Apache and Passenger work together in handling
> resources+requests. This confusion came about primarily because of one
> passenger-memory-stats output.
>
> Apache processes - ### Processes: 11 ### Total private dirty RSS: 2.58
> MB
> Passenger processes - ## Processes: 10 ### Total private dirty RSS:
> 268.52 MB
>
> Now I thought that since the parent mod_passenger sits inside the
> parent Apache process and inside every other worker process, the total
> private dirty values should match. But they're nowhere even close!
> Where did I go wrong there?

I'm not sure how you understood it, but they're all separate
processes. The two totals should not be compared with each other.


> I think Im missing how the directives for both these servers affect
> each other.
>
> For Apache, im using the default prefork_mpm with the following
> settings
>
> StartServers - 5
> MinSpareServers - 5
> MaxSpareServers - 10
> MaxClients - 150
> MaxRequestsPerChild - 0
>
> I want to understand how these map to/affect Passenger's own
> directives listed below

They don't. The Apache MPM settings are totally disjoint from Phusion
Passenger's process management settings. With the MPM settings you're
just configuring how Apache itself is behaving.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Ram

unread,
Jun 6, 2010, 7:38:52 AM6/6/10
to Phusion Passenger Discussions
Hi Hongli,

Thank you for the response! Let me put my question this way... If im
sending 100 requests, 5 concurrent requests at a time to the server
and the Apache settings are as above and Passenger has default
settings, could you describe how the requests traverse the server
setup?

I understand that this is a very broad question and there may be
different answers depending on how fast/slow the app itself is. But
assuming that there are no long standing requests (ie. 10 reqs/sec
receive 10 responses/sec), could you explain how the requests traverse
the Apache - Passenger - Rails - App path?

Thanks again!

On Jun 3, 2:52 pm, Hongli Lai <hon...@phusion.nl> wrote:
> On Wed, Jun 2, 2010 at 9:28 AM, Ram <yourstruly.vi...@gmail.com> wrote:
> > Hi,
>
> > Ive got Passenger 2.0.6 and Apache 2 setup for a Rails app staging
> > server running standard Ruby (not REE). Im trying to optimize the
> > setup using tools like ab (Apache Bench) to gather metrics and
> > passenger-memory-stats to study the memory usage (since I hear 'top'
> > is extremely misleading -http://ahref.in/e4407).
> E-mail: i...@phusion.nl

Hongli Lai

unread,
Jun 6, 2010, 8:24:32 AM6/6/10
to phusion-...@googlegroups.com
On Sun, Jun 6, 2010 at 1:38 PM, Ram <yourstru...@gmail.com> wrote:
> Hi Hongli,
>
> Thank you for the response! Let me put my question this way... If im
> sending 100 requests, 5 concurrent requests at a time to the server
> and the Apache settings are as above and Passenger has default
> settings, could you describe how the requests traverse the server
> setup?
>
> I understand that this is a very broad question and there may be
> different answers depending on how fast/slow the app itself is. But
> assuming that there are no long standing requests (ie. 10 reqs/sec
> receive 10 responses/sec), could you explain how the requests traverse
> the Apache - Passenger - Rails - App path?

There is a pool of app processes. Whenever the web server receives a
request it checks out an app process from the pool and marks it as
busy. If all app processes in the pool are busy and the pool limit
hasn't been reached yet, then a new one will be spawned. The web
server then proceeds with communicating with the checked out app
process. This means that, as a rule, your web server's concurrency
level must be at least equal to PassengerMaxPoolSize, which is usually
the case. Setting your web server's concurrency level above
PassengerMaxPoolSize won't gain you any more performance or additional
concurrency as far as Phusion Passenger requests are concerned, but
may help you with other things like serving static assets.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl

Ram

unread,
Jun 6, 2010, 10:22:21 AM6/6/10
to Phusion Passenger Discussions
Apache's current Concurrency Level at any given time is defined by the
output "### Processes: " of sudo passenger-memory-stats right? And it
can be defined by the directives - StartServers, MinSpareServers and
MaxSpareServers?

And Passenger's spawn server, framework spawner and application
spawner are independent of these processes described above right? In
terms of memory usage that is.

So typically, would you say that the following formula is good for a
single app running on a slice?

(total private dirty for Apache processes) + (total private dirty for
Passengers spawn servers) + (PassengerMaxPoolSize * Private dirty per
app instance) should be = 80% of slice memory (with a leeway of 20%
for stuff like mysql, SSHing into the server, etc.)

Some other clarifications, if you will, on the directives,

1. PassengerMaxInstancesPerApp is relevant only if you're running
multiple apps on the same slice. And if you are, it will always be
lesser than PassengerMaxPoolSize and probably a factor of it .. ?

2. PassengerPoolIdleTime can typically be set to infinite (0) for a
slice running a single app and configured with the above formula, so
that app instances are always ready to process client requests and the
app instance spawning time is saved .. ?

3. PassengerMaxRequests, again would typically be infinite (0) with
the given setup and PassengerStatThrottleRate wouldn't need to be
touched given that it is a dedicated slice for one app .. ?

4. Apache's MaxClients directive can now be decided based on the avg
response time from the application and what is an acceptable waiting
time for the customer. Say,
(Avg response time * (MaxClients - 1)) / Concurrency would be =
Waiting time for last client in queue .. ?

Thanks Hongli! :) Hope im not freaking you out with all the
questions! :D



On Jun 6, 5:24 pm, Hongli Lai <hon...@phusion.nl> wrote:
> E-mail: i...@phusion.nl

Ram

unread,
Jun 8, 2010, 4:27:56 AM6/8/10
to Phusion Passenger Discussions
Hongli .. ? Did I overload? :)

Would really appreciate it if you could reply to my last post. Its
hard to find all this information in one place on the net. Am looking
to put it together in a blog post so that it can be of use to others
but I need to make sure that my understanding is right first. Hope you
can assist me with that.

Cheers!

Hongli Lai

unread,
Jun 8, 2010, 6:22:09 AM6/8/10
to phusion-...@googlegroups.com
On Tue, Jun 8, 2010 at 10:27 AM, Ram <yourstru...@gmail.com> wrote:
> Hongli .. ? Did I overload? :)
>
> Would really appreciate it if you could reply to my last post. Its
> hard to find all this information in one place on the net. Am looking
> to put it together in a blog post so that it can be of use to others
> but I need to make sure that my understanding is right first. Hope you
> can assist me with that.
>
> Cheers!
>
> On Jun 6, 7:22 pm, Ram <yourstruly.vi...@gmail.com> wrote:
>> Apache's current Concurrency Level at any given time is defined by the
>> output "### Processes: " of sudo passenger-memory-stats right? And it
>> can be defined by the directives - StartServers, MinSpareServers and
>> MaxSpareServers?

It's defined entirely by the MPM settings like StartServers and stuff.
The number of Apache processes only indicates Apache's concurrency
level if you're using the prefork MPM. When using the worker MPM each
process can have multiple threads so the number of processes becomes
meaningless in that case.


>> And Passenger's spawn server, framework spawner and application
>> spawner are independent of these processes described above right? In
>> terms of memory usage that is.

Yes.


>> So typically, would you say that the following formula is good for a
>> single app running on a slice?
>>
>> (total private dirty for Apache processes) + (total private dirty for
>> Passengers spawn servers) + (PassengerMaxPoolSize * Private dirty per
>> app instance) should be = 80% of slice memory (with a leeway of 20%
>> for stuff like mysql, SSHing into the server, etc.)

Yes looks good as a general guideline. Things can vary depending on
your app or server so be sure to experiment with the values.


>> Some other clarifications, if you will, on the directives,
>>
>> 1. PassengerMaxInstancesPerApp is relevant only if you're running
>> multiple apps on the same slice. And if you are, it will always be
>> lesser than PassengerMaxPoolSize and probably a factor of it .. ?

Yes.


>> 2. PassengerPoolIdleTime can typically be set to infinite (0) for a
>> slice running a single app and configured with the above formula, so
>> that app instances are always ready to process client requests and the
>> app instance spawning time is saved .. ?

Yes.


>> 3. PassengerMaxRequests, again would typically be infinite (0) with
>> the given setup

Yes. It's actually only good for broken apps that leak memory and need
to be restarted once in a while.


> and PassengerStatThrottleRate wouldn't need to be
>> touched given that it is a dedicated slice for one app .. ?

Yes. StatThrottleRate is designed to reduce load on NFS servers.
Typically has no effect on the local filesystem unless your filesystem
is very very very slow for some reason.


>> 4. Apache's MaxClients directive can now be decided based on the avg
>> response time from the application and what is an acceptable waiting
>> time for the customer. Say,
>> (Avg response time * (MaxClients - 1)) / Concurrency would be =
>> Waiting time for last client in queue .. ?

I don't know for sure, Apache's concurrency settings keep confusing me
so every time I configure it I have to re-read its docs carefully, and
I still wouldn't feel like I fully understand it. :) This is a
question that's best asked to the Apache developers I think.


>> Thanks Hongli! :) Hope im not freaking you out with all the
>> questions! :D

You're welcome.

--
Phusion | The Computer Science Company

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl

Ram

unread,
Jun 8, 2010, 6:39:36 AM6/8/10
to Phusion Passenger Discussions
Hongli, thanks a bunch! Appreciate the help! :)

On Jun 8, 3:22 pm, Hongli Lai <hon...@phusion.nl> wrote:
> E-mail: i...@phusion.nl

deepak

unread,
Jun 28, 2010, 7:30:28 AM6/28/10
to Phusion Passenger Discussions
+1
@Ram please comment with the link to the blog post when done.

Ram

unread,
Jul 8, 2010, 8:15:54 AM7/8/10
to Phusion Passenger Discussions
Hey Guys,

As promised - http://ahref.in/55599 :).

this is just part 1. Working on two other parts which i will link to
here as well.

Ram

unread,
Jul 25, 2010, 5:25:50 AM7/25/10
to Phusion Passenger Discussions
Part 2 - Apache and Passenger Directives -
http://tenmiles.com/blog/2010/07/understanding-optimizing-your-server-part-2-apache-passenger-directives/

On Jul 8, 5:15 pm, Ram <yourstruly.vi...@gmail.com> wrote:
> Hey Guys,
>
> As promised -http://ahref.in/55599 :).
>
> this is just part 1. Working on two other parts which i will link to
> here as well.
>
> On Jun 28, 4:30 pm, deepak <kannan.dee...@gmail.com> wrote:
>
>
>
> > +1
> > @Ram please comment with the link to the blog post when done.
>
> > On Jun 8, 1:27 pm, Ram <yourstruly.vi...@gmail.com> wrote:
>
> > > Hongli .. ? Did I overload? :)
>
> > > Would really appreciate it if you could reply to my last post. Its
> > > hard to find all this information in one place on the net. Am looking
> > > to put it together in a blog post so that it can be of use to others
> > > but I need to make sure that myunderstandingis right first. Hope you
> > > can assist me with that.
>
> > > Cheers!
>
> > > On Jun 6, 7:22 pm, Ram <yourstruly.vi...@gmail.com> wrote:
>
> > > >Apache'scurrent Concurrency Level at any given time is defined by the
> > > > output "### Processes: " of sudopassenger-memory-stats right? And it
> > > > can be defined by thedirectives- StartServers, MinSpareServers and
> > > > MaxSpareServers?
>
> > > > AndPassenger'sspawn server, framework spawner and application
> > > > spawner are independent of these processes described above right? In
> > > > terms of memory usage that is.
>
> > > > So typically, would you say that the following formula is good for a
> > > > single app running on a slice?
>
> > > > (total private dirty forApacheprocesses) + (total private dirty for
> > > > Passengers spawn servers) + (PassengerMaxPoolSize * Private dirty per
> > > > app instance) should be = 80% of slice memory (with a leeway of 20%
> > > > for stuff like mysql, SSHing into the server, etc.)
>
> > > > Some other clarifications, if you will, on thedirectives,
>
> > > > 1. PassengerMaxInstancesPerApp is relevant only if you're running
> > > > multiple apps on the same slice. And if you are, it will always be
> > > > lesser than PassengerMaxPoolSize and probably a factor of it .. ?
>
> > > > 2. PassengerPoolIdleTime can typically be set to infinite (0) for a
> > > > slice running a single app and configured with the above formula, so
> > > > that app instances are always ready to process client requests and the
> > > > app instance spawning time is saved .. ?
>
> > > > 3. PassengerMaxRequests, again would typically be infinite (0) with
> > > > the given setup and PassengerStatThrottleRate wouldn't need to be
> > > > touched given that it is a dedicated slice for one app .. ?
>
> > > > 4.Apache'sMaxClients directive can now be decided based on the avg
> > > > response time from the application and what is an acceptable waiting
> > > > time for the customer. Say,
> > > > (Avg response time * (MaxClients - 1)) / Concurrency would be =
> > > > Waiting time for last client in queue .. ?
>
> > > > Thanks Hongli! :) Hope im not freaking you out with all the
> > > > questions! :D
>
> > > > On Jun 6, 5:24 pm, Hongli Lai <hon...@phusion.nl> wrote:
>
> > > > > On Sun, Jun 6, 2010 at 1:38 PM, Ram <yourstruly.vi...@gmail.com> wrote:
> > > > > > Hi Hongli,
>
> > > > > > Thank you for the response! Let me put my question this way... If im
> > > > > > sending 100 requests, 5 concurrent requests at a time to the server
> > > > > > and theApachesettings are as above andPassengerhas default
> > > > > > settings, could you describe how the requests traverse the server
> > > > > > setup?
>
> > > > > > I understand that this is a very broad question and there may be
> > > > > > different answers depending on how fast/slow the app itself is. But
> > > > > > assuming that there are no long standing requests (ie. 10 reqs/sec
> > > > > > receive 10 responses/sec), could you explain how the requests traverse
> > > > > > theApache-Passenger- Rails - App path?
>
> > > > > There is a pool of app processes. Whenever the web server receives a
> > > > > request it checks out an app process from the pool and marks it as
> > > > > busy. If all app processes in the pool are busy and the pool limit
> > > > > hasn't been reached yet, then a new one will be spawned. The web
> > > > > server then proceeds with communicating with the checked out app
> > > > > process. This means that, as a rule, your web server's concurrency
> > > > > level must be at least equal to PassengerMaxPoolSize, which is usually
> > > > > the case. Setting your web server's concurrency level above
> > > > > PassengerMaxPoolSize won't gain you any more performance or additional
> > > > > concurrency as far as PhusionPassengerrequests are concerned, but
Reply all
Reply to author
Forward
0 new messages