即使只有一个用户,Apache也使用100%的CPU
每当有人在我们的bug跟踪器中search错误,或者只是重新加载search结果页面或者对结果进行sorting,Apache(或者我应该通过Apache来说PHP吗?)使用100%CPU几秒钟。
这会导致非常缓慢的页面加载。 即使我从服务器机器本身访问我们的bug跟踪器,也会发生这种情况。
我的问题是什么似乎是这里的瓶颈(Apacheconfiguration,PHPconfiguration,MySQLconfiguration,caching,PHP模块或其他?),我应该怎么做才能解决它?
我们正在使用的软件(几个月前下载,之后没有更新):
Kubuntu:14.04.3 LTS
PHP:5.5.9(我猜是运行Apache apache mod?CGI?似乎不是fastCGI)
apache2:2.4.7(PREFORK)
mysql:5.5.44
Bug Genie(bug跟踪软件):4.1.0
这是Firebug的图像。
“POST分页”是一个重要的,它需要1秒接收4.0M,但它必须等待7秒才能收到。
这是“POST分页”标题的图像。

就像服务器一样,它是这样做的。
看来“分页”的请求需要7-8秒来处理。
第一波是当我search和显示约250个问题(“分页”),第二个是当我采取一个小动作就像去一个问题页面。 你可以看到,即使是小的行动占用CPU。

我不知道为什么使用这么多的内存(1.6G的2.0G),即使我不访问错误跟踪器,但无论如何,空闲内存似乎已经足够了。

似乎并不存在I / O问题(“%iowait”低,有时候“await”可能比“svctm”更大)

而且似乎没有太多的交换。
这是我们的设置(可能对我的猜测重要的部分)。
Apache2.conf(不使用httpd.conf)
ServerName localhost Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 HostnameLookups Off <Directory /var/www/html/bugs2/> Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all </Directory> AccessFileName .htaccess
将ServerName更改为127.0.0.1没有帮助。
我也尝试添加下面的文本到apache.conf,但它不会改变任何东西。 我想这是因为已经有mpm_prefork.conf这是非常接近(只有MaxRequestWorkers是150)。
<IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 20 MaxRequestsPerChild 0 </IfModule>
的.htaccess
<IfModule mod_php5.c> php_flag magic_quotes_gpc off php_flag register_globals off </IfModule> Options +FollowSymlinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /bugs2/public/ RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(.*)$ index.php?url=$1 [NC,QSA,L] RewriteCond %{REQUEST_URI} \..+$/ RewriteCond %{REQUEST_URI} !\.(html|wsdl|json|xml)$ RewriteRule .* - [L] RewriteRule ^(.*)$ index.php?url=$1 [NC,QSA,L] RedirectMatch 403 ^/\.svn(/|$) </IfModule>
几天前,我也把mod_expires,mod_headers,mod_deflate,mod_gzip放到.htaccess中,但是在CPU使用率或加载速度之前/之后我看不到任何区别。
<IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 24 hours" ExpiresByType application/json "access plus 1 months" ExpiresByType image/jpg "access plus 1 months" ExpiresByType image/gif "access plus 1 months" ExpiresByType image/jpeg "access plus 1 months" ExpiresByType image/png "access plus 1 months" ExpiresByType text/css "access plus 1 months" ExpiresByType text/javascript "access plus 1 months" ExpiresByType application/javascript "access plus 1 months" ExpiresByType application/x-shockwave-flash "access plus 1 months" ExpiresByType application/x-javascript "access plus 1 months" ExpiresByType application/pdf "access plus 1 months" ExpiresByType image/x-icon "access plus 1 year" </IfModule> <ifModule mod_headers.c> <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public, no-transform" </filesMatch> <filesMatch "\\.(css)$"> Header set Cache-Control "max-age=604800, public" </filesMatch> <filesMatch "\\.(js)$"> Header set Cache-Control "max-age=216000, private" </filesMatch> <filesMatch "\\.(xml|txt)$"> Header set Cache-Control "max-age=216000, public, must-revalidate" </filesMatch> <filesMatch "\\.(html|htm|php)$"> Header set Cache-Control "max-age=1, private, must-revalidate" </filesMatch> Header unset ETag Header unset Last-Modified </ifModule> <IfModule mod_deflate.c> SetOutputFilter DEFLATE BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary SetEnvIfNoCase Request_URI _\.utxt$ no-gzip AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php AddOutputFilterByType DEFLATE application/json </IfModule> <ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl|json)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule>
我也尝试在mod_expires的部分使用filesMatch而不是ExpiresByType,它也没有帮助。
在php.ini
engine = On output_buffering = 4096 disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, disable_classes = zend.enable_gc = On expose_php = On max_execution_time = 30 max_input_time = 60 memory_limit = 128M
顺便说一下,我可以看到运行phpinfo()时的其他内存限制

但可能没关系。
my.cnf中
bind-address = localhost skip-external-locking skip-name-resolve key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP query_cache_limit = 1M query_cache_size = 16M
交换绑定地址到127.0.0.1没有帮助。
安装Php模块
Bcmath Bz2 Calendar Core Ctype Curl Date Dba Dom Ereg Exif Fileinfo Filter ftp gd gettext hash iconv json libxml mbstring mhash mysql mysqli openssl pcntl pcre PDO Pdo_mysql Phar Posix Readline Reflection Session Shmop SimpleXML Soap Sockets SPL Standard Sysvmsg Sysvsem Sysvshm Tokenizer Wddx Xml Xmlreader Xmlwriter Zend OPcache Zip Zlib
我已经了解到,有时php模块会导致这种事情,但我并没有试图一个一个地阻止它们。 另外,我不太确定,但似乎OPcache正在工作。 
Apache模块安装
Core_module (static) So_module (static) watchdog_module (static) http_module (static) log_config_module (static) version_module (static) unixd_module (static) access_compat_module (shared) alias_module (shared) auth_basic_module (shared) authn_core_module (shared) authn_file_module (shared) authz_core_module (shared) authz_host_module (shared) authz_user_module (shared) autoindex_module (shared) deflate_module (shared) dir_module (shared) env_module (shared) filter_module (shared) mime_module (shared) mpm_prefork_module (shared) negotiation_module (shared) php5_module (shared) rewrite_module (shared) setenvif_module (shared) status_module (shared)
访问和错误日志不显示任何特别的或可疑的。