一次 linux +apache + apache module性能诊断以及调优过程
第1章 系统架构为linux +apache + apache module程序。
第2章 具体的os以及apache信息:
[admin@test1 logs]$ uname -a
Linux test12.6.9-42.ELsmp #1 SMP Wed Jul 12 23:32:02 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux
[admin@test1 logs]$ /usr/local/apache2/bin/httpd -l
Compiled in modules:
core.c
mod_authn_file.c
mod_authn_default.c
mod_authz_host.c
mod_authz_groupfile.c
mod_authz_user.c
mod_authz_default.c
mod_auth_basic.c
mod_include.c
mod_filter.c
mod_log_config.c
mod_env.c
mod_setenvif.c
worker.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_cgid.c
mod_negotiation.c
mod_dir.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_so.c
[admin@test1 logs]$ /usr/local/apache2/bin/httpd -v
Server version: Apache/2.2.6(Unix)
Server built: Jan 31 2008 20:42:34
第3章 性能场景设置
36 vuser,pacing: 0.25秒。期望tps为140次/秒。
第4章 调优之前
httpd.conf为:
<IfModule worker.c>
StartServers 2
ServerLimit 2
MaxClients 20
MinSpareThreads 10
MaxSpareThreads 20
ThreadsPerChild 10
MaxRequestsPerChild 0
</IfModule>
性能测试结果如下:
第5章 性能分析
响应时间不满足性能需求。
加入apache module分析apache,接收到http接收到请求+处理+发送网络包的时间为:
10.0.4.132 - - [21/Feb/2008:17:18:13 +0800] "GET /bin/search?news_gb?nk=Y&_PS=pt&_SS=id&n=1&series_id=59197&_id=1001028515 HTTP/1.1" 200 1547 "cost 0 ms"
10.0.4.132 - - [21/Feb/2008:17:18:13 +0800] "GET /bin/search?news_gb?parents=3000103,&_PS=pt&n=5&q=tags%3A%22%C5%AE%CA%BD%B8%DF%D1%A5%22+&O=and&news_type=8,9,10,11,12,13,14,15&_id=1001292049 HTTP/1.1" 200 5162 "cost 2 ms"
10.0.4.132 - - [21/Feb/2008:17:18:13 +0800] "GET /bin/search?news_gb?_PS=pt&s=4&n=6&q=tags%3A%22%B7%FE%D7%B0%B3%B1%C1%F7%22+&O=and&news_type=8,9,10,11,12,13,14,15 HTTP/1.1" 200 49647 "cost 6 ms"
从上述看,apache接到http请求后的处理速度很快。
另外,分析IO(无si/so )、网络(300Kbytes)、CPU都不是特别高。
[admin@test1 logs]$ vmstat 2 10
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 17936 2320460 9680 2086580 0 5 54 59 27 14 2 1 96 1
0 1 17936 2323468 9680 2088280 0 0 806 0 9948 1172 47 10 27 15
2 2 17936 2321356 9680 2088960 0 0 314 0 8780 1023 36 8 48 8
5 0 17936 2318348 9688 2090380 0 0 670 118 6669 1051 37 6 43 14
3 0 17936 2285324 9688 2091876 0 0 754 0 11847 1405 37 12 35 16
1 1 17936 2287260 9696 2092820 0 0 458 116 12115 1400 40 13 38 9
0 1 17936 2298588 9696 2093160 0 0 140 0 8620 856 37 8 52 4
0 2 17936 2300572 9696 2094928 0 0 872 0 8497 1145 34 12 41 12
[admin@test1 logs]$ sar -n DEV 2 10
Linux2.6.9-42.ELsmp (test1) 02/21/2008
05:27:20 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
05:27:22 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:27:22 PM eth0 2984.34 5652.02 182552.02 8365743.94 0.00 0.00 0.00
05:27:22 PM veth31 3.03 2.02 783.84 133.33 0.00 0.00 0.00
05:27:22 PM sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:27:22 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
05:27:24 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:27:24 PM eth0 1989.05 3622.89 134824.38 5310582.09 0.00 0.00 0.00
05:27:24 PM veth31 5.47 2.49 4040.30 1696.52 0.00 0.00 0.00
05:27:24 PM sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:27:24 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
05:27:26 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:27:26 PM eth0 2207.46 4199.00 145106.97 6175783.08 0.00 0.00 0.00
05:27:26 PM veth31 5.97 3.98 1314.43 1018.41 0.00 0.00 0.00
05:27:26 PM sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
由于loadrunner设置36个并发。而httpd.conf MaxClients 20
,36〉20 (线程),造成loadrunner并发排队。
诊断为并发数过高而httpd.conf配置不当,导致apache httpd线程阻塞,造成等待队列过长。
第6章 调优
程序不变。增加Maxclients
更改httpd.conf为:
<IfModule worker.c>
StartServers 2
ServerLimit 2
MaxClients 40
MinSpareThreads 10
MaxSpareThreads 20
ThreadsPerChild 20
MaxRequestsPerChild 0
</IfModule>
LoadModule responseCost_module /usr/local/apache2/modules/mod_responseCost.so
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{responseCost}n\"" common
性能表现如下,可见吞吐率都大幅度提升,响应时间下降。
如果是prefork编译,则httpd.conf采用
<IfModule prefork.c>
ServerLimit 40
StartServers 5
MinSpareServers 5