2012-11-29 22 views
2

我今天注意到,當從我們的Web服務器發出請求時,事情相當緩慢。 我開始研究它,並且我發現一個根擁有apache進程的負載。多個Apache根進程

我不確定這實際上是什麼導致事情變得緩慢,但是沒有更多,它看起來不太好。

問題是,我不知道從這裏做什麼? 如何找出爲什麼有這麼多的根進程? 可以推薦一些測試嗎?我已經嘗試過對他們中的一些進行攔截,他們似乎在做某些事情,但strace的輸出超出了我的想象。

root  30918 1.8 1.3 84284 52296 ?  Ss 14:11 0:01 /usr/sbin/apache2 -k restart 
root  30919 0.0 1.1 84420 45612 ?  S 14:11 0:00 /usr/sbin/apache2 -k restart 
root  30920 0.0 1.1 84420 45604 ?  S 14:11 0:00 /usr/sbin/apache2 -k restart 
root  30921 0.0 1.1 84420 45612 ?  S 14:11 0:00 /usr/sbin/apache2 -k restart 
root  30922 0.1 1.1 84420 45612 ?  S 14:11 0:00 /usr/sbin/apache2 -k restart 
root  30923 0.0 1.1 84420 45612 ?  S 14:11 0:00 /usr/sbin/apache2 -k restart 
www-data 30926 6.6 1.5 104964 61336 ?  S 14:12 0:03 /usr/sbin/apache2 -k restart 
root  30930 0.1 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30933 0.0 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30935 0.0 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30936 0.0 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30937 0.0 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30938 0.0 1.1 84420 45616 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30961 0.0 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30989 0.0 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  30990 0.0 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  31011 0.1 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  31013 0.1 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  31014 0.0 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31175 2.5 1.5 104168 60524 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31189 2.3 1.4 102360 58920 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31190 1.5 1.4 101904 58356 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31191 0.3 1.1 84556 46760 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31192 1.4 1.4 101916 58384 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
www-data 31193 1.5 1.4 101916 58376 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 
root  31240 0.1 1.1 84420 45612 ?  S 14:12 0:00 /usr/sbin/apache2 -k restart 

這是來自其中一個進程的strace輸出示例。

--- SIGCHLD (Child exited) @ 0 (0) --- 
read(6, 0xff87f6ef, 1)     = -1 EAGAIN (Resource temporarily unavailable) 
getuid32()        = 0 
close(17)        = 0 
gettimeofday({1354109303, 670988}, NULL) = 0 
semop(5668864, {{0, -1, SEM_UNDO}}, 1) = 0 
accept(4, {sa_family=AF_INET, sin_port=htons(48107), sin_addr=inet_addr("192.168.16.12")}, [16]) = 17 
fcntl64(17, F_GETFD)     = 0 
fcntl64(17, F_SETFD, FD_CLOEXEC)  = 0 
semop(5668864, {{0, 1, SEM_UNDO}}, 1) = 0 
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xf74a2768) = 1949 
waitpid(1949, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 1949 
--- SIGCHLD (Child exited) @ 0 (0) --- 
read(6, 0xff87f6ef, 1)     = -1 EAGAIN (Resource temporarily unavailable) 
getuid32()        = 0 
close(17)        = 0 
gettimeofday({1354109305, 724358}, NULL) = 0 
semop(5668864, {{0, -1, SEM_UNDO}}, 1) = 0 
accept(4, {sa_family=AF_INET, sin_port=htons(48132), sin_addr=inet_addr("192.168.16.12")}, [16]) = 17 
fcntl64(17, F_GETFD)     = 0 
fcntl64(17, F_SETFD, FD_CLOEXEC)  = 0 
semop(5668864, {{0, 1, SEM_UNDO}}, 1) = 0 
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xf74a2768) = 1974 
waitpid(1974, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 1974 
--- SIGCHLD (Child exited) @ 0 (0) --- 

我已禁用啓用MODS,除了像權威性,ENV,siteenv和別名必不可少的人都在模塊並啓動服務器。在這種情況下,我仍然得到6個根apache進程和1個www-data擁有apache進程。

我已經確定所有模塊都是up2date。

日誌中沒有明顯的錯誤。

config按照;

ServerRoot "/etc/apache2" 

LockFile /var/lock/apache2/accept.lock 

PidFile ${APACHE_PID_FILE} 

Timeout 300 

KeepAlive On 

MaxKeepAliveRequests 100 

KeepAliveTimeout 15 

<IfModule mpm_worker_module> 
StartServers   2 
MaxClients   150 
MinSpareThreads  25 
MaxSpareThreads  75 
ThreadsPerChild  25 
MaxRequestsPerChild 0 
</IfModule> 

User ${APACHE_RUN_USER} 
Group ${APACHE_RUN_GROUP} 

AccessFileName .htaccess 

<Files ~ "^\.ht"> 
Order allow,deny 
Deny from all 
</Files> 

DefaultType text/plain 


HostnameLookups Off 

ErrorLog /var/log/apache2/error.log 

LogLevel warn 

Include /etc/apache2/mods-enabled/*.load 
Include /etc/apache2/mods-enabled/*.conf 

Include /etc/apache2/httpd.conf 

Include /etc/apache2/ports.conf 

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 
LogFormat "%h %l %u %t \"%r\" %>s %b" common 
LogFormat "%{Referer}i -> %U" referer 
LogFormat "%{User-agent}i" agent 

CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined 

Include /etc/apache2/conf.d/ 

Include /etc/apache2/sites-enabled/ 

的模塊編譯如下:編譯模塊 : core.c mod_log_config.c mod_logio.c itk.c http_core.c mod_so.c

所以我現在只運行mpm_worker配置。

DEBUG UPDATER 
When I restart apache, and ps, I get something like this; 
    root  26921 0.5 1.3 80008 52452 ?  Ss 21:27 0:02 /usr/sbin/apache2 -k start 
    root  27114 0.0 1.1 80144 44804 ?  S 21:34 0:00 /usr/sbin/apache2 -k start 
    root  27115 0.0 1.1 80144 44820 ?  S 21:34 0:00 /usr/sbin/apache2 -k start 
    root  27116 0.0 1.1 80144 44804 ?  S 21:34 0:00 /usr/sbin/apache2 -k start 
    root  27117 0.0 1.1 80144 44804 ?  S 21:34 0:00 /usr/sbin/apache2 -k start 
    root  27119 0.0 1.1 80144 44804 ?  S 21:34 0:00 /usr/sbin/apache2 -k start 

如果我把LogLevel的調試和重新啓動,然後我看到mod_proxy的

[Thu Nov 29 21:34:01 2012] [info] Server built: Sep 9 2012 21:17:36 
[Thu Nov 29 21:34:01 2012] [debug] itk.c(1100): AcceptMutex: sysvsem (default: sysvsem) 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 27115 for worker proxy:reverse 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 27114 for worker proxy:reverse 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 27115 for (*) 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 27114 for (*) 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 27117 for worker proxy:reverse 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 27117 for (*) 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 27119 for worker proxy:reverse 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 27119 for (*) 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 27116 for worker proxy:reverse 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized 
[Thu Nov 29 21:34:01 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 27116 for (*) 
[Thu Nov 29 21:36:20 2012] [notice] SIGHUP received. Attempting to restart 

通知PID相匹配這些消息。但是,如果我禁用mod_proxy,那麼這些消息會消失,但我仍然會得到相同數量的根進程,因此我認爲這不是一個原因。

+0

你還可以顯示你的httpd.conf跳過評論嗎?這可能有助於更好地理解你的設置。同時檢查我在答案中描述的內容。這也可能有所幫助。然而現在我沒有看到任何惡意,除了太多的根進程而不是www-data。 – AlexKey

+0

hi - config新增 – mark

+0

這是一個老問題,但是你有沒有得到任何解決方案?我在Debian中有一個相同的問題。父apache進程以root身份啓動幾個子進程,其中一些啓動一個由www-data所擁有的單個子進程。 – stockli

回答

2

這對Apache來說是絕對正常的。每個進程一次處理一個請求。所以如果只有一個進程(它被稱爲worker),那麼如果有很多用戶,它會很慢。

我看到的問題是這些不應該是根擁有的進程。根據你的平臺,它應該有它自己的用戶。就像在Debian中,用戶將是www-data。那麼只有一個進程將由root擁有,其餘的將由該用戶擁有。

但速度是由幾個因素 - 硬件,Web服務器和Web應用程序定義的。

請確保您在運行的硬件符合要求(足夠的內存和CPU)

下的工人在惡劣的硬件能力的情況下,或增加,如果它是超級好。

確保Web應用程序(如果有的話,並且通常是PHP應用程序)不是性能的瓶頸。

PS:對不起格式不好的,從手機上打出來的。

+0

嗨亞歷克斯,那的確是我的問題 - 對不起,如果它不明確。他們爲什麼有這麼多的根進程?我是否知道他們在做什麼?如果他們我們都是www數據流程的話,我會很高興。然而,有6個根擁有的進程(當我啓動服務器時)爲每個萬維網數據進程做一些事情,它並不是那種方式。 – mark

+0

@mark好吧,這就是爲什麼我希望看到你的配置,以便我們可以從基礎開始調查;) – AlexKey

+0

啊 - 對不起,我錯過了你的評論。配置添加。 – mark

0

知道我對比賽有點遲,但我遇到了同樣的問題,並試圖弄清楚發生了什麼。我在Apache 2.4.7上比你更新,但總體前提是一樣的。

我不得不尋找在/etc/apache2/mods-enabled/mpm_prefork.conf找到我的MPM配置,但你就在這裏:

<IfModule mpm_worker_module> 
StartServers   2 
MaxClients   150 
MinSpareThreads  25 
MaxSpareThreads  75 
ThreadsPerChild  25 
MaxRequestsPerChild 0 
</IfModule> 

看起來像一個有效的配置,它是。然而,像我的MaxRequestsPerChild那樣,它被設置爲0.我已將它調整到大約10(可能會更高,但現在只是測試),我認爲這解決了我的問題。希望這可以幫助!