我有一个简单的PHP脚本运行在Apache 2.2上(几乎是默认的configuration)。 当运行命令ab -n 1 <address> ,其中地址是本地IP或域名,我收到约15秒的窗口保持打开状态,收到所有的数据在第一秒左右。
当用浏览器浏览同一页面时,我得到的是100分钟以内的回应。 据我所知,大多数现代浏览器都支持Keep-Alive标头,并用某种TTL定时器存储持久连接。 所以,当我运行ab -kn <whatever>命令时,我开始通过浏览器获得更接近我期望的性能的结果。
这是正常的行为? 我的服务器configuration有不正确的地方吗?
[编辑]
我已经用-v 2标志再次运行了ab ,这是输出:
Benchmarking localhost (be patient)...INFO: POST header == --- GET <PATH> HTTP/1.0 Host: localhost User-Agent: ApacheBench/2.3 Accept: */* --- LOG: header received: HTTP/1.1 200 OK Date: Sat, 02 Apr 2011 05:09:42 GMT Server: Apache/2.2.16 (Ubuntu) Vary: Accept-Encoding Content-Length: 86 Content-Type: text/html <html><head><title>Dynamic</title><body><h1>This is another action!</h1></body></html> ..done Server Software: Apache/2.2.16 Server Hostname: localhost Server Port: 80 Document Path: <PATH> Document Length: 86 bytes Concurrency Level: 1 Time taken for tests: 15.076 seconds Complete requests: 1 Failed requests: 0 Write errors: 0 Total transferred: 242 bytes HTML transferred: 86 bytes Requests per second: 0.07 [#/sec] (mean) Time per request: 15075.916 [ms] (mean) Time per request: 15075.916 [ms] (mean, across all concurrent requests) Transfer rate: 0.02 [Kbytes/sec] received
但是,浏览器也接受了PHP的zlib压缩的Content-Encoding: gzip和97的内容长度 – 可能还有Apache 2.2的deflate特性。 在整个身体被发送之后,在..done之前发生15秒的暂停。
我想你会问,“在返回之前, ab -n 1是否正常等待连接拆除(15秒),即使服务器立即发送所有数据?
这不正常。
运行verbosity = 2( ab -v 2 <url> ),然后检查返回的头文件。 服务器是否发送Connection:close? 它是否发送了不正确的Content-Length?
[编辑]
我现在看到你的身体是一条线,所以也许ab在实体之后没有得到CR LF是不快乐的。 我不能用apache和一个文本文件重现那种输出–apache在body之后添加了CR LF,ab立即返回。 你怎么生产这个输出?
在将这些标题添加到服务器的响应之后为我工作
连接:保持活动内容长度:xxx
奇怪的是,如果我没有添加'连接'标题,在'-k'模式下ab超时。 看起来像在实施中的一些错误。