Apache和Tomcat之间的延迟
我们有一个设置,其中我们有一个弹性LB,它将负载分布在两个Apache服务器A1和A2上。这些apache服务器呈现一些php页面,主要将API请求重定向到tomcat应用程序服务器T1和T2,如下图所示:Apache和Tomcat之间的延迟,apache,tomcat,mod-proxy,tomcat8,Apache,Tomcat,Mod Proxy,Tomcat8,我们有一个设置,其中我们有一个弹性LB,它将负载分布在两个Apache服务器A1和A2上。这些apache服务器呈现一些php页面,主要将API请求重定向到tomcat应用程序服务器T1和T2,如下图所示: Incoming Request | | | \/ LB /\ / \ / \ A1 A2 |\ /| | \ / | | \ / | | / \ | T1 T2 我们最近开始注意到ap
Incoming Request
|
|
|
\/
LB
/\
/ \
/ \
A1 A2
|\ /|
| \ / |
| \ / |
| / \ |
T1 T2
我们最近开始注意到apache和tomcat之间的延迟。以下是apache mod_slow log和tomcat access log中针对同一请求的日志行示例:
APACHE_MOD_SLOW: VNSdtwoAAJkAACnXb-cAAACJ [06/Feb/2015:16:25:51 +0530] elapsed: 50.58 cpu: 0.00(usr)/0.00(sys) pid: 10711 ip: 10.0.0.153 host: www.example.com:443 reqinfo: GET /data/v1/url?url=test-508324 HTTP/1.1
TOMCAT: [06/Feb/2015:16:26:42 +0530] "GET /data/v1/url?url=test-508324 HTTP/1.1" 200 65 10
Apache表示,收到的请求是在06/Feb/2015:16:25:51+0530
时发出的,处理请求需要50秒。而tomcat表示只需10毫秒
即可处理请求,而它是在06/Feb/2015:16:26:42+0530
收到请求的
这意味着apache花了将近50秒的时间连接并将整个请求发送给tomcat。Apache正在使用mod\u proxy\u ajp
连接到Apache。以下是配置:
<Proxy balancer://prod>
BalancerMember ajp://127.0.0.1:8009 route=jvmRoute-8009 connectiontimeout=1 retry=300
BalancerMember ajp://10.0.0.153:8009 route=jvmRoute-8009 connectiontimeout=1 retry=300
ProxySet lbmethod=byrequests
</Proxy>
下面的观察让我相信,糟糕的性能取决于事件的顺序,因为测试中没有一个请求执行得那么糟糕
版本:
Apache:2.2.4
Tomcat:8.0.16
是否知道延迟来自何处以及如何减少延迟?通常,这种延迟表示响应的内容长度无效,并且用户代理(在本例中为httpd)在最终超时连接之前等待其预期的其余响应。检查您的响应头并使用-k和ab来使用keep-alive,因为这更可能触发此类问题。@马克:我们可能不是这种情况,因为tomcat最终以200状态代码提供了请求,假设Apache和tomcat以及lb和Apache之间存在keep-alive。如果没有,请检查netstat。@Khanna111GauravKhanna:keep-alive是否存在DNS/反向DNS问题?我认为tcpdump或wireshark可以提供很多信息。甚至netstat。您可以使用类似于:watch-n1“netstat-ntp | grep8009”的内容来监视连接的情况。
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" maxThreads="4096" minSpareThreads="25" maxSpareThreads="75"/>
ab -n5000 -c5 https://example.com/test/100001
Requests per second: 13.67 [#/sec] (mean)
Time per request: 365.851 [ms] (mean)
Time per request: 73.170 [ms] (mean, across all concurrent requests)
Transfer rate: 79.96 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 236 267 95.5 247 3401
Processing: 83 98 58.6 89 1959
Waiting: 82 96 57.5 87 1959
Total: 319 365 134.0 338 3571
Percentage of the requests served within a certain time (ms)
50% 338
66% 347
75% 356
80% 364
90% 399
95% 477
98% 689
99% 869
100% 3571 (longest request)
ab -n5000 -c5 http://example.com/test/100001
Time per request: 186.015 [ms] (mean)
Time per request: 37.203 [ms] (mean, across all concurrent requests)
Transfer rate: 155.55 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 74 79 33.4 76 1278
Processing: 83 107 82.3 91 3964
Waiting: 82 105 60.9 89 940
Total: 157 186 90.1 168 4042
Percentage of the requests served within a certain time (ms)
50% 168
66% 174
75% 180
80% 184
90% 211
95% 259
98% 379
99% 507
100% 4042 (longest request)
ab -n5000 -c5 http://IP:8080/test/100001
Requests per second: 31.32 [#/sec] (mean)
Time per request: 159.624 [ms] (mean)
Time per request: 31.925 [ms] (mean, across all concurrent requests)
Transfer rate: 181.30 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 71 76 68.4 73 3079
Processing: 78 84 13.1 81 594
Waiting: 77 83 6.5 81 185
Total: 149 159 71.2 154 3313
Percentage of the requests served within a certain time (ms)
50% 154
66% 157
75% 160
80% 161
90% 166
95% 171
98% 177
99% 189
100% 3313 (longest request)