LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Multiple instances of apache2 running? (https://www.linuxquestions.org/questions/linux-newbie-8/multiple-instances-of-apache2-running-4175449996/)

idofxeno 02-13-2013 10:09 AM

Multiple instances of apache2 running?
 
I couldn't connect to my server last night while I was at work, so once I got home I checked to see if the server was still on and it was (Had a power outage last week that cause me some issues so I thought that could have been it). I did ps aux | more and saw multiple entries of apache2:

Code:

eric@fate ~ $ ps aux | grep apache2
root      1741  0.0  0.1 175636  9912 ?        Ss  10:54  0:00 /usr/sbin/apache2 -k start
www-data  1890  0.0  0.1 175860  6728 ?        S    10:54  0:00 /usr/sbin/apache2 -k start
www-data  1891  0.0  0.0 175684  6060 ?        S    10:54  0:00 /usr/sbin/apache2 -k start
www-data  1892  0.0  0.1 175708  6300 ?        S    10:54  0:00 /usr/sbin/apache2 -k start
www-data  1893  0.0  0.1 175700  6300 ?        S    10:54  0:00 /usr/sbin/apache2 -k start
www-data  1894  0.0  0.1 175860  6568 ?        S    10:54  0:00 /usr/sbin/apache2 -k start
www-data  2069  0.0  0.1 175860  6568 ?        S    10:56  0:00 /usr/sbin/apache2 -k start
www-data  2070  0.0  0.0 175660  5808 ?        S    10:57  0:00 /usr/sbin/apache2 -k start
eric      2879  0.0  0.0  13584  940 pts/1    S+  11:00  0:00 grep --colour=auto apache2

I have no idea why it's doing this, but I feel pretty sure it has something to do with my troubles last night. When I checked it before I rebooted, there were like 30 instances of it running. After reboot, it was only like 5, but the number seems to randomly increase the longer the computer is on. Any idea what's going on?

chrism01 02-13-2013 05:46 PM

When Apache starts (as you can see its started as root), then drops privs to the named owner (www-data) and starts a given num of listeners, defined in httpd.conf as per the StartServers setting https://httpd.apache.org/docs/2.2/mo...l#startservers.
See also related directives like MaxClients etc on the same page.

idofxeno 02-14-2013 08:32 AM

Quote:

Originally Posted by chrism01 (Post 4891111)
When Apache starts (as you can see its started as root), then drops privs to the named owner (www-data) and starts a given num of listeners, defined in httpd.conf as per the StartServers setting https://httpd.apache.org/docs/2.2/mo...l#startservers.
See also related directives like MaxClients etc on the same page.

Ok I think I understand what I read there, but again this morning I came home and checked and saw the following:

Code:

eric@fate ~ $ ps aux | grep apache2
root      1497  0.0  0.1 175636  9948 ?        Ss  Feb13  0:02 /usr/sbin/apache2 -k start
www-data  5986  0.0  0.1 180100 11640 ?        S    03:23  0:02 /usr/sbin/apache2 -k start
www-data  6061  0.0  0.1 178992 10464 ?        S    03:33  0:01 /usr/sbin/apache2 -k start
www-data  6157  0.0  0.1 180108 11572 ?        S    03:43  0:00 /usr/sbin/apache2 -k start
www-data  6158  0.0  0.1 180100 11648 ?        S    03:43  0:10 /usr/sbin/apache2 -k start
www-data  6161  0.0  0.1 178968 10292 ?        S    03:43  0:00 /usr/sbin/apache2 -k start
www-data  6221  0.0  0.1 178704 10032 ?        S    03:46  0:00 /usr/sbin/apache2 -k start
www-data  6290  0.0  0.1 178704  9864 ?        S    03:50  0:00 /usr/sbin/apache2 -k start
www-data  6409  0.0  0.1 178668  9912 ?        S    03:53  0:00 /usr/sbin/apache2 -k start
www-data  6411  0.0  0.1 179188 10696 ?        S    03:53  0:00 /usr/sbin/apache2 -k start
www-data  7425  0.0  0.1 176204  7928 ?        S    05:42  0:00 /usr/sbin/apache2 -k start
www-data  7490  0.0  0.1 178412  9712 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7491  0.0  0.1 178436  9552 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7492  0.0  0.1 179640 10752 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7493  0.0  0.1 178436  9440 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7494  0.0  0.1 179188 10584 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7495  0.0  0.1 178552  9796 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7496  0.0  0.1 178452 10060 ?        S    05:52  0:00 /usr/sbin/apache2 -k start
www-data  7526  0.0  0.1 178440  9428 ?        S    05:56  0:00 /usr/sbin/apache2 -k start
www-data  7527  0.0  0.1 178452  9800 ?        S    05:56  0:00 /usr/sbin/apache2 -k start
www-data  7534  0.0  0.1 178404  9564 ?        S    05:56  0:00 /usr/sbin/apache2 -k start
www-data  7540  0.0  0.1 176204  7952 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7541  0.0  0.1 179200 10652 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7542  0.0  0.1 178436  9488 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7544  0.0  0.1 178440  9404 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7545  0.0  0.1 178192  9564 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7546  0.0  0.1 178440  9404 ?        S    05:57  0:00 /usr/sbin/apache2 -k start
www-data  7547  0.0  0.1 176204  7932 ?        S    05:58  0:00 /usr/sbin/apache2 -k start
www-data  7548  0.0  0.1 175960  7788 ?        S    05:58  0:00 /usr/sbin/apache2 -k start
www-data  7549  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7550  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7551  0.0  0.1 176112  7932 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7552  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7553  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7554  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7555  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7556  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7557  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7558  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7559  0.0  0.1 176112  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7562  0.0  0.1 178412  9628 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7563  0.0  0.1 179188 10452 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7564  0.0  0.1 178456  9512 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7565  0.0  0.1 176204  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7566  0.0  0.1 176204  7940 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7567  0.0  0.1 178440  9380 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7568  0.0  0.1 176204  7928 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7569  0.0  0.1 178552  9776 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7570  0.0  0.1 178436  9404 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7571  0.0  0.1 178440  9400 ?        S    05:59  0:00 /usr/sbin/apache2 -k start
www-data  7573  0.0  0.1 176204  7944 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7574  0.0  0.1 178456  9944 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7575  0.0  0.1 178536 10124 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7576  0.0  0.1 181268 12052 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7577  0.0  0.1 178552  9752 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7578  0.0  0.1 178440  9392 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7579  0.0  0.1 178712  9744 ?        S    06:00  0:00 /usr/sbin/apache2 -k start
www-data  7605  0.0  0.1 176204  7932 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7606  0.0  0.1 176204  7928 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7607  0.0  0.1 178436  9384 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7609  0.0  0.1 178436  9392 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7613  0.0  0.1 176464  7968 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7614  0.0  0.1 176464  7968 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7615  0.0  0.1 176464  7968 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7616  0.0  0.1 176204  7944 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7617  0.0  0.1 178276  9392 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7618  0.0  0.1 177920  9132 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7619  0.0  0.1 176252  8192 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  7620  0.0  0.1 178452  9524 ?        S    06:01  0:00 /usr/sbin/apache2 -k start
www-data  8727  0.0  0.1 180412 11528 ?        S    08:11  0:00 /usr/sbin/apache2 -k start
www-data  9281  0.0  0.1 179232 10628 ?        S    09:23  0:00 /usr/sbin/apache2 -k start
www-data  9282  0.0  0.1 176204  7936 ?        S    09:23  0:00 /usr/sbin/apache2 -k start
www-data  9283  0.0  0.1 176204  7928 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9284  0.0  0.1 176204  7936 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9285  0.0  0.0 175676  6056 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9286  0.0  0.0 175676  6056 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9288  0.0  0.0 175660  5808 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9289  0.0  0.0 175660  5808 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9290  0.0  0.0 175660  5808 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9291  0.0  0.0 175660  5808 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
www-data  9292  0.0  0.0 175660  5808 ?        S    09:24  0:00 /usr/sbin/apache2 -k start
eric      9320  0.0  0.0  13584  940 pts/1    S+  09:25  0:00 grep --colour=auto apache2

Obviously that's a ridiculous number of processes and isn't normal. What I'm trying to figure out is what may be causing the issue. The only thing I can think of is that I do have a Glype proxy script running on a directory on the web server that a few of my coworkers (only 3 of them have the url) use occasionally to bypass the content filter at work. Does anyone know if there is some sort of bug where the child processes aren't being terminated after the client closes out of the script? Or could it be something else?

chrism01 02-14-2013 07:37 PM

Like I said, check the (several) related directives eg MaxCLients; there's also one that dictates how many requests an instance serves before it shuts down.
I'd also check the access_log and error_log to see where the requests are coming from & why.

idofxeno 02-14-2013 11:10 PM

my httpd.conf doesn't have anything aside from servername localhost, so default MaxClients should be 256. What I don't understand is 1) Why are child processes not being terminated when someone uses glype proxy, 2) How reducing MaxClients (or any of the other settings) is going to impact anything to me site related. As far as I can imagine, the only thing I can think of is that at a certain point it's just going to stop allowing people to access the site at all because it will enter a queue until the child processes are terminated, which won't happen until I figure out why glype acts this way, manually go in and kill all of those processes myself, or I restart the server. There are only 3 people using the proxy on the website, and according to the glype logs they are solely using it to view content on youtube at this point, so I fail to see why I would have that many remaining child processes going unless it was some issue with glype. I guess I'll just remove glype until I can figure it out. Thanks for your help.

r0b0 02-15-2013 03:18 AM

But why are you worried? Do you experience some performance problems with this server? If everything is running normally, why do you bother killing processes and restarting the server? I say, let apache do its job, if it needs 256 processes to do it, so be it.

pintooo15 02-15-2013 03:37 AM

I suppose this is why lightweight alternatives exist.

idofxeno 02-15-2013 04:10 AM

Well the main reason is because I suspect it to be part of the reason why I was unable to connect to my server the other day. The modem was alive and when I got home everything appeared to be fine but I couldn't connect still. Checked processes and saw what I've already posted. After restarting, everything worked fine. Went to work and everything was fine until someone came to me saying it was no longer loading content from glype. Checked processes and boom 70 apache processes again. Restart fixed it again. The only thing Ive seen that correlates with the issue is the abundance of child processes that haven't been killed.

Im no expert by any stretch, but I equate it to how you need to delete objects in C++ or they occupy memory indefinitely unless the program exits.

pintooo15 02-19-2013 11:56 PM

From what I found on the net, Apache 2 will spawn and keep extra processes ready to service any new clients. How much resources it uses for this ought to be configurable, though I haven't gone through the details. You may also look into MPM worker module http://httpd.apache.org/docs/2.2/mod/worker.html to control thread spawning.

idofxeno 02-20-2013 12:05 AM

Quote:

Originally Posted by pintooo15 (Post 4895688)
From what I found on the net, Apache 2 will spawn and keep extra processes ready to service any new clients. How much resources it uses for this ought to be configurable, though I haven't gone through the details. You may also look into MPM worker module http://httpd.apache.org/docs/2.2/mod/worker.html to control thread spawning.

Thanks, I will be looking into this tonight. On another note, I'm apparently not the only one with this issue ( http://www.netbuilders.org/web-proxi...lype-5860.html ) So I'm going to follow the thread and check out the worker module link and see where it all leads.

pintooo15 02-20-2013 10:19 AM

idofxeno, if you know for sure, you won't be serving like a humongous userbase. consider seriously the option of shifting to a lightweight and excellent for smaller sites webserver. nginx and lighttpd come to mind. They are very underrated. First thing to find would be if there are specific dependencies on Apache and how the alternatives can possibly satisfy those.

ashwin_cse 02-20-2013 12:08 PM

having multiple httpd processes running is perfectly normal behaviour and is nothing to worry about.

pintooo15 02-20-2013 02:45 PM

It is a matter to worry about if your system slows to a crawl and doesn't function even at least as a webserver itself.

jpollard 02-20-2013 03:30 PM

Quote:

Originally Posted by pintooo15 (Post 4896218)
It is a matter to worry about if your system slows to a crawl and doesn't function even at least as a webserver itself.

Then impose a proper MaxClients limit.

count them as 5 per processor (you could also divide your memory size by the data space used by apache, then subtract 10. If the result is below 10, use 10.)

The only reason to allow apache to multi-thread is support concurrent connections. If that overloads the system, the only reasonable thing to do is limit the number threads to what the hardware will support.

256 might be reasonable for my system (8GB with 8 cores), but personally, 10 is enough.

ashwin_cse 02-20-2013 10:59 PM

Quote:

Originally Posted by pintooo15 (Post 4896218)
It is a matter to worry about if your system slows to a crawl and doesn't function even at least as a webserver itself.

Running multiple instances of processes is not a reason for slowing down to crawl. Reason would be when these processes spikes cpu utilization and mem utilization. Usual situations that happens is when you have high traffic or bad code or combination of both. I have seen apache spawn mulitple instances even when there is little traffic and this behaviour has not caused the server to slow down. My server had xeon quad core cpu and 8GB ram. Basically you are looking at the wrong place for the reason for system's slow response.

idofxeno 02-21-2013 07:11 PM

Quote:

Originally Posted by jpollard (Post 4896235)
Then impose a proper MaxClients limit.

count them as 5 per processor (you could also divide your memory size by the data space used by apache, then subtract 10. If the result is below 10, use 10.)

The only reason to allow apache to multi-thread is support concurrent connections. If that overloads the system, the only reasonable thing to do is limit the number threads to what the hardware will support.

256 might be reasonable for my system (8GB with 8 cores), but personally, 10 is enough.

[Quote from link I posted]..."This isn't just the processes hanging for a little bit - or hanging for a few hours. They're hanging indefinitely. Not only does the Apache session hang - but the request from the client hangs as well. For example, if you go to google.com through a proxy, and it hangs, that request hangs forever as well. Now every time you try to connect back to the server it tries to send you to that Apache child. Which essentially makes the server unresponsive to you." -- pretty much describes EXACTLY what I'm experiencing, so my best guess is that it's a Glype-specific issue rather than an issue with Apache itself (I could be wrong though, feel free to speculate). I have made some modifications to apache2.conf and will monitor the situation in the meantime to see if it helps with the issues I've been experiencing (Specifically lowering MaxClients and other settings, however error logs showed MaxClients being hit around the time when I starting noticing the problems initially, so hopefully lowering the value isn't going to exacerbate the problem).

pintooo15 02-22-2013 12:53 AM

ashwin_cse , I didn't make it clear that I was not just pointing at the large number of processes that get spawned but also how exponentially the resource usage grows with each new child spawned...which may further be compounded by the reasons you gave.

Lots for me to learn from this thread. :)


All times are GMT -5. The time now is 08:20 PM.