[英]netty: the http file example can not work with apache bench when keep-alive is enabled
正在测试的http文件示例: https : //github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/file
我用netty-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 [3.1]中的3.1。 每个标题字段均由名称,后跟冒号(“:”)和字段值组成。 字段名称不区分大小写。 字段值可以在任何数量的LWS之前,尽管首选单个SP。 通过在每条额外的行之前添加至少一个SP或HT,可以将标题字段扩展到多行。 在生成HTTP构造时,应用程序应遵循“通用形式”,即已知形式或表示形式,因为某些实现可能无法接受通用形式以外的任何形式。
因为ApacheBench的keep-alive开关强制其假定服务器支持keep alive,所以它不会为keep alive数据包检测到“丢失”标头。
但是,此问题是应该在ApacheBench中解决的问题,因为这是该应用程序中的一个错误,导致它错过了正确的内容长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.