logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Third-party Modules View previous topic :: View next topic
Reply to topic   Topic: How Apache Works process/threads ?
Author
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Thu 17 Apr '14 17:34    Post subject: How Apache Works process/threads ? Reply with quote

Can someone explain how does Apache works? I see when I start Apache server, 2 httpd processes get created.
I understand one is the parent, other is the child.
What do they do?
I also see that other httpd processes are started and that they are also children. Why and what do they do?

I am asking the basic questions since I am a complete novice in Apache so please elaborate.
I am working on a shared Apache module written in Delphi 7 which is acting as a server for client applications running on Windows Mobile 5.0 devices.

Much appreciated,
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Sun 20 Apr '14 19:22    Post subject: Reply with quote

A single control process (the parent) is responsible for launching child processes. Each child process creates a fixed number of server threads as specified, as well as a listener thread which listens for connections and passes them to a server thread for processing when they arrive.

This is how it basicly works for all mpms except prefork mpm.
Back to top
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Tue 22 Apr '14 22:17    Post subject: Reply with quote

So, my parent httpd will create one child httpd process for each request coming in or?
Thank you
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 22 Apr '14 22:43    Post subject: Reply with quote

Well there are a hand full of different mpms.
Each is working a bit differently.

Netware mpm_netware
OS/2 mpmt_os2
Unix prefork, worker, or event, depending on platform capabilities
Windows mpm_winnt

Here, 'Unix' is used to mean Unix-like operating systems, such as Linux, BSD, Solaris, Mac OS X, etc.


The way you described it is as prefork mpm works. The others work with threads instead of processes.

Please read

http://httpd.apache.org/docs/current/en/mod/mpm_winnt.html

http://httpd.apache.org/docs/current/en/mod/prefork.html

http://httpd.apache.org/docs/current/en/mod/event.html
Back to top
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Tue 22 Apr '14 23:19    Post subject: Reply with quote

Thanks James,
So, on Windows (mpm_winnt), a single parent creates a single child which then creates ThreadsPerChild (as set in httpd-mpm.conf) threads to process incoming requests. By looking at my setting for example, that number is 25.

This tells me that there will be always only 1 parent and 1 child httpd process but I see different in Task Manager. I see sometimes 5, 6 httpd processes once of which is parent but others are children.
One of these will evenually reach memory cap of 2GB and if that happens, user has to manually restart Apache.
I am trying to understand how apache works to figure out why is one of the httpd processes growing in memory and not all of them.

In my case, I can have any number of barcode scanning device talk to database through an apache shared module file.
Say I have 5 devices connected, does it mean I will have 6 httpd processes running? (1 for parent, 5 for children)?

Much appreciated.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Wed 23 Apr '14 20:46    Post subject: Reply with quote

There can be only 2 httpd.exe processes in your taskmanager. Shocked
There is 1 parent and 1 child. The child will start a number of threads (defined ThreadsPerChild). In your example 25. Those threads will serv the client connections. Don't forget that http is "fire and forget". After a thread has finished serving a request it is free to serv the next request.

There can be only one process listen to a single port. Which is the parent process. Are you sure your tool doesn't show the threads? Are you talking about the windows default task manager?
Back to top
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Wed 23 Apr '14 21:10    Post subject: Reply with quote

James, thanks for your reply.
On my dev machine, I have only 2 but on client, I have seen 5, 6, 7, 8 (usually btw 5 and 10) httpd processes. I have seen only one of these growing in memory until 2GB cap is reached when it crashes and Apache must be manually restarted.
Yes, I am talking about Windows Task Manager. It will show 6-8 httpd processes. One is parent; others are children. I have shared google drive location with the image showing it.


UPDATE
To explain a bit, there could be any number of devices connecting to the shared module running on apache server. On my system, I have only one device or emulator, but clients might use 20 devices. Could that be the reason there are multiple httpd processes showing in in Windows Task Manager?
Much appreciated,

https://drive.google.com/folderview?id=0BzdoGfp97QQbemxYN2tqQmU4NTQ&usp=sharing
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 24 Apr '14 18:23    Post subject: Reply with quote

I'm puzzled! Please use http://technet.microsoft.com/de-de/sysinternals/bb896653.aspx and upload that picture, too... since there are only 2 processes on windows ...
Back to top
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Thu 24 Apr '14 18:33    Post subject: Reply with quote

James, the link is to the German site to download Process Explorer. Is it the correct link?
Thanks for your help.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 24 Apr '14 20:11    Post subject: Reply with quote

You could have just change the language Wink

http://technet.microsoft.com/en-US/en-en/sysinternals/bb896653.aspx
Back to top
_db_



Joined: 16 Apr 2014
Posts: 8
Location: Canada

PostPosted: Fri 25 Apr '14 20:20    Post subject: Reply with quote

James, thanks for your help.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 29 Apr '14 15:40    Post subject: Reply with quote

The sreenshot?
Back to top


Reply to topic   Topic: How Apache Works process/threads ? View previous topic :: View next topic
Post new topic   Forum Index -> Third-party Modules