A simple Dart HTTP server hangs on Apache Bench
-
21-06-2021 - |
Question
I have this Google Dart test program:
#import('dart:io');
main() {
var s = new HttpServer();
s.defaultRequestHandler = (HttpRequest req, HttpResponse res) {
res.statusCode = 200;
res.contentLength = 4;
res.outputStream.writeString("sup!!");
res.outputStream.close();
};
s.listen('127.0.0.1', 80);
print('its up!');
}
It works fine on Chrome and Firefox, I get the sup -messages.
However, as soon as I try Apache Bench against it, it hangs (ab
hangs):
Z:\www>ab -n 1 -c 1 "http://127.0.0.1/"
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)...apr_poll: The timeout specified has expired (70007)
You can find ab
by installing Apache HTTP server and it will be located under the bin
folder.
On a side note: is there some other benchmarking tool similar to ab
that I could possibly use (and does not hang)?
Solution
It could be a problem with the contentLength. You wrote 4, but the actual content length is 5. For instance, if ab saw the contentLength, it might read 4 characters and wait for the connection to close. However, the connection probably won't close because the server is waiting to write the last character. The client and server are each waiting for something, resulting in deadlock.