网状:当保活启用
下测试HTTP文件例如HTTP文件例如不能与Apache钳工工作: https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/file网状:当保活启用
我编译网状-4.1.0.beta8上面的例子。
My test result:
$ ab -k -n 2 -c 1 -v 6 http://127.0.0.1:8080/test.sh
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)...INFO: POST header ==
---
GET /test.sh HTTP/1.0
Connection: Keep-Alive
Host: 127.0.0.1:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
content-length: 462
content-type: application/octet-stream
date: Fri, 26 Feb 2016 06:34:52 GMT
expires: Fri, 26 Feb 2016 06:35:52 GMT
cache-control: private, max-age=60
last-modified: Fri, 19 Feb 2016 02:35:40 GMT
connection: keep-alive
LOG: Response code = 200
LOG: header received:
**MY TEST.SH CONTENT**
WARNING: Response code not 2xx (500)
apr_poll: The timeout specified has expired (70007)
Total of 1 requests completed
看来我的test.sh内容被认为是第二个请求的标题。
我进一步测试:
$ ab -k -n 1 -c 1 -v 6 http://127.0.0.1:8080/test.sh
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)...INFO: POST header ==
---
GET /test.sh HTTP/1.0
Connection: Keep-Alive
Host: 127.0.0.1:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
content-length: 462
content-type: application/octet-stream
date: Fri, 26 Feb 2016 06:39:02 GMT
expires: Fri, 26 Feb 2016 06:40:02 GMT
cache-control: private, max-age=60
last-modified: Fri, 19 Feb 2016 02:35:40 GMT
connection: keep-alive
LOG: Response code = 200
..done
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8080
Document Path: /test.sh
Document Length: 0 bytes
Concurrency Level: 1
Time taken for tests: 0.005 seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Keep-Alive requests: 1
Total transferred: 263 bytes
HTML transferred: 0 bytes
Requests per second: 209.25 [#/sec] (mean)
Time per request: 4.779 [ms] (mean)
Time per request: 4.779 [ms] (mean, across all concurrent requests)
Transfer rate: 53.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 5 5 0.0 5 5
Waiting: 5 5 0.0 5 5
Total: 5 5 0.0 5 5
你可以看到文件长度为0字节。
我对www.google.com运行类似的命令,它工作正常。 你能帮忙吗?提前致谢。
这是ApacheBench中的一个错误。
ApacheBench并未完全遵循http规范,并且假定标头具有一定的大小写。由于netty应用程序返回的头文件没有ApacheBench期望的字符大小写,因此它假定内容长度的默认值为0个字节。
HTTP报头字段,其中包括通用头(第4.5节), 请求头(第5.3节),响应头(第6.2节),和 实体标题(第7.1节)字段中,遵循RFC 822 [9]第3.1节中给出的相同通用格式 。每个标题字段由 组成,后跟一个冒号(“:”)和字段值。 字段名称 不区分大小写。该字段值可以前面有任何数量的 LWS,但首选SP。通过在每条额外的行前加上至少一个SP 或HT,可以在多行上扩展标头字段 。应用程序应该遵循“通用形式”,其中一个是已知的 或生成HTTP构造时指示的,因为可能存在一些实现不能接受任何超出常见形式的实现。
由于ApacheBench的keep-alive开关强制它假定服务器支持保持活动状态,因此它不会检测到保持活动数据包的“丢失”标头。
这个问题是否应该在ApacheBench中解决,因为它是该应用程序中导致错过正确内容长度的错误。
它是否工作,如果'-k'被删除? – ZhongYu
是的。我的服务器在发送每个响应后关闭非保持活动http连接。在这种情况下,ApacheBench知道它是套接字输入流的结束。 –