You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Xin Tong <xe...@gmail.com> on 2012/05/28 22:10:16 UTC

[users@httpd] apache http running in multithreaded mode

Hello

I am new to apache httpd. I noticed that apache httpd spawns many
processes to server user request. one of the httpd process is the
master (i.e. running with root id on linux). the other ones are it
children ( i.e. running with daemon id). is the master httpd process
kind of like a load dispatcher and the ones running with daemon like
the workers ? Is there a way to build apache such that it does not
spawn new processes. instead it spawns new threads within the root
process to handle incoming request ?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache http running in multithreaded mode

Posted by Mark Montague <ma...@catseye.org>.
On May 28, 2012 16:10 , Xin Tong <xe...@gmail.com> wrote:
> I noticed that apache httpd spawns many
> processes to server user request. one of the httpd process is the
> master (i.e. running with root id on linux). the other ones are it
> children ( i.e. running with daemon id). is the master httpd process
> kind of like a load dispatcher and the ones running with daemon like
> the workers ? Is there a way to build apache such that it does not
> spawn new processes. instead it spawns new threads within the root
> process to handle incoming request ?

Run "httpd -V" and look at the line "Server MPM".  What you describe 
above sounds most like the prefork MPM ( 
https://httpd.apache.org/docs/2.4/mod/prefork.html ) but what you want 
is probably the event MPM ( 
https://httpd.apache.org/docs/2.4/mod/event.html ) if you are running 
httpd 2.4, or the worker MPM ( 
https://httpd.apache.org/docs/2.4/mod/worker.html ) if you are running 
httpd 2.2.

If you are running Apache HTTP Server 2.4, and it was built with the 
option "--enable-mpms-shared=all" then you do not need to rebuild httpd 
in order to switch to a different MPM.  If you are running 2.4 without 
this option, or if you are running 2.2, then you might need to rebuild 
httpd -- but some Linux distributions (such as Red Hat, CentOS, Fedora) 
will provide multiple versions of httpd, each with a different MPM, and 
you can either switch to the right version ( like /usr/sbin/httpd.worker 
) or install it as a separate package.

Note that even if you use the event or worker MPM, there will be 
multiple httpd processes.  But each process will use threads to handle 
requests.  This is better than the prefork MPM where each processes 
handles only one request at a time.  For performance and scalability 
reasons, it would be bad to have only one process that handles 
everything via threads.  In the special case where you are trying to 
debug httpd, you can start it with the -X option to limit it to a single 
worker in a single process.

--
   Mark Montague
   mark@catseye.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache http running in multithreaded mode

Posted by Bill Unruh <un...@physics.ubc.ca>.
On Mon, 28 May 2012, Xin Tong wrote:

> Hello
>
> I am new to apache httpd. I noticed that apache httpd spawns many
> processes to server user request. one of the httpd process is the
> master (i.e. running with root id on linux). the other ones are it
> children ( i.e. running with daemon id). is the master httpd process
> kind of like a load dispatcher and the ones running with daemon like
> the workers ? Is there a way to build apache such that it does not
> spawn new processes. instead it spawns new threads within the root
> process to handle incoming request ?

If you want to rewrite it, go ahead. It has an open license.

It spawns processes so that it can quickly service a new request coming in by
dispensing it to the waiting process. You can control the min and max numbers
of such waiting processes with the 
MinSpareServers and MaxSpareServers directives in the mpm_prefork_module
module description.(the former is what it starts out with, the latter what it
settles down to with a reasonably active host).

  (I learned about this recently when I found my system with 160 waiting
processes and the system swapping itself to death. No idea what went wrong,
but after upgrading it has stayed pretty consistent at 20 (which is wha tthe
MaxSpareServers is set to)

It also does use threads. I think to handle multiple requests -- eg all the
pictures on a web page-- on one main request.





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org