简体   繁体   中英

netty: the http file example can not work with apache bench when keep-alive is enabled

The http file example under test: https://github.com/netty/netty/tree/4.1/example/src/main/java/io/netty/example/http/file

I compiled the above example with 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

It seemed that my test.sh content is considered to be the second request's headers.

My further test:

$ 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

You can see the document length is 0 byte.

I run similar commands against www.google.com and it works fine. Could you please help on this? Thanks in advance.

This is a bug in ApacheBench.

ApacheBench does not follow the http specifications fully, and assumes headers have a certain capitalization. Because the headers returned by the netty application doesn't have the character case ApacheBench expects, it assumes a default of 0 bytes for the content length.

Http specification 4.2:

HTTP header fields, which include general-header (section 4.5), request-header (section 5.3), response-header (section 6.2), and entity-header (section 7.1) fields, follow the same generic format as that given in Section 3.1 of RFC 822 [9]. Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. The field value MAY be preceded by any amount of LWS, though a single SP is preferred. Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT. Applications ought to follow "common form", where one is known or indicated, when generating HTTP constructs, since there might exist some implementations that fail to accept anything beyond the common forms.

Because the keep-alive switch of ApacheBench forces it to assume the server supports keep alive, it doesn't detect a "missing" header for the keep alive packet.

This problem if however something that should be solved in ApacheBench, as it is a bug in that application that causes it to miss the proper content-length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM