Jun 21, 2012

HTTP Server in Scala and Java 7

HTTP server written in Scala using Asynchronous Socket in Java 7. The server reads entire HTTP header in request and responds back with simple HTML. This by no means is meant to provide complete HTTP protocol implementation. The main purpose is to demonstrate the AIO in Java 7 and simplicity of Scala syntax.

And it is also quite performant. Notice the thread pool with one thread only. Using Apache HTTP server benchmarking tool it achieves easily 20kreq/s:
$ ab -c100 -n100000 "http://localhost:8000/"

Time taken for tests: 4.953 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 12200000 bytes
HTML transferred: 2000000 bytes
Requests per second: 20190.79 #/sec
Time per request: 4.953 ms
Time per request: 0.050 ms
Transfer rate: 2405.54 [Kbytes/sec] received

No comments:

Post a Comment