====== AsyncHTTPD ======
Is web server without any locks and synchronizations. Is written in pure Java, uses NIO nonblocking channels and Kilim lightweight threads. Is designed to handle MANY concurrent connections, internally can handle 100 000! connections simultaneously. And everything with a few threads and small memory requirements.
==== Changes ====
* 7.9.2008 - I wrote [[blog:writing_fast_nio_webserver| article]] which explains some internals and what is wrong with Channel selector.
* 29.8.2008 - new alpha M2, code changes to make sure small chunks are send in one packet
* 26.8.2008 - first alpha release M1
==== Download ====
{{asynchttpd-m2.zip|Milestone 2}}
{{asynchttpd-m1.zip|Milestone 1}}
==== Why? ====
Because it is fun. Also asynchronous programing is challenging and this server is good demonstration.
AsyncHTTP can be wery usefull for task, where high performance is required and JSP/J2EE are too slow. It makes possible to dump memory based data directly to channel without blocking. It is pure Java, so it is not needed to give up confort for speed.
==== How? ====
AsyncHTTPD is using [[http://kilim.malhar.net/| Kilim]] which brings Erlang style programming to Java. Kilim provides lightweight threads, so it is possible to alocate new micro-thread for each connection. It is not problem to have millions! micro-threads running simultaneously.
And of course it needs some optimalization.
==== Where is the catch? ====
Because there are no locks and no waiting, AsyncHTTPD is constantly running in an infinitive cycle. It means that it consumes all CPU power on single core even when serving single connection. It does not consume CPU when idle.
Kilim lightweight threads require slightly different programming style. It also needs bytecode manipulation after compilation.
==== Performace ====
It is too early to validate performance, so here is just simple comparation.
Serving 4 KB file on Athlon 2 GHz single core, Ubuntu 8.04. Client and server are running on the same computer.
In short: AsyncHTTPD is comparable to other NIO Java servers and 2 times slower then optimized server written in C.
First AsyncHTTPD, async-listen, no logging
jan@artemis:~$ http_load -parallel 1000 -second 5 url.txt
12704 fetches, 992 max parallel, 4.54041e+07 bytes, in 5.00055 seconds
3574 mean bytes/connection
2540.52 fetches/sec, 9.07983e+06 bytes/sec
msecs/connect: 97.8715 mean, 3009.45 max, 0.047 min
msecs/first-response: 19.106 mean, 3020.72 max, 2.423 min
HTTP response codes:
code 200 -- 12704
Grizzly HTTP webserver
jan@artemis:~$ http_load -parallel 1000 -second 5 urlg.txt
11988 fetches, 917 max parallel, 4.28451e+07 bytes, in 5.00279 seconds
3574 mean bytes/connection
2396.26 fetches/sec, 8.56425e+06 bytes/sec
msecs/connect: 192.678 mean, 3030.3 max, 0.052 min
msecs/first-response: 16.7581 mean, 3003.07 max, 2.786 min
HTTP response codes:
code 200 -- 11988
Now [[http://www.lighttpd.net/| LIGHTTPD]] with default configuration
jan@artemis:~$ http_load -parallel 1000 -second 5 url8.txt
26490 fetches, 258 max parallel, 9.46753e+07 bytes, in 5.00051 seconds
3574 mean bytes/connection
5297.45 fetches/sec, 1.89331e+07 bytes/sec
msecs/connect: 14.6115 mean, 3001.73 max, 0.045 min
msecs/first-response: 3.00292 mean, 2999.74 max, 1.611 min
HTTP response codes:
code 200 -- 26490