Feeds

I had tested a hello world web server in C, Erlang, Java and the Go programming language.
* C, use the well-known high performance web server nginx, with a hello world nginx module
* Erlang/OTP
* Java, using the MINA 2.0 framework, now the JBoss Netty framework.
* Go, http://golang.org/

in nginx.conf, set “worker_processes 1; worker_connections 10240″ for 1 cpu test, set “worker_processes 4; worker_connections 2048″ for multi-core cpu test. Turn off all access or debug log in nginx.conf, as follows

$ erlc ehttpd.erl
$ taskset -c 1 erl +K true +h 99999 +P 99999 -smp enable +S 2:1 -s ehttpd
$ taskset -c 1-7 erl +K true -s ehttpd
We use taskset to limit erlang vm to use only 1 CPU/core or use all CPU cores. The 2nd line is run in single CPU mode, and the 3rd line is run in multi-core CPU mode.

Java source code, save the 2 class as HttpServer.java and HttpProtocolHandler.java, and do necessary import.

Nov 24 update Because the above Mina code doesn’t parse HTTP request and handle the necessary HTTP protocol, replaced with org.jboss.netty.example.http.snoop.HttpServer from Netty example, but removed all the string builder code from HttpRequestHandler.messageReceived() and just return a “hello world” result in HttpRequestHandler.writeResponse(). Please read the source code and the Netty documentation for more information.

2.2 latency, 99% requests within(ms)

30

100

1,000

5,000

Nginx html(1C)

1

4

42

3,079

Nginx module(1C)

1

4

32

3,047

Nginx module(Multi-core)

1

6

205

3,036

Erlang(1C)

3

8

629

6,337

Erlang(Multi-Core)

2

7

223

3,084

Java, Netty

1

3

3

3,084

Go

26

33

47

9,005

3. Notes

* On large concurrent connections, C, Erlang, Java no big difference on their performance, results are very close.
* Java runs better on small connections, but the code in this test doesn’t parse the HTTP request header (the MINA code).
* Although Mr. Yu Feng (the Erlang guru in China) mentioned that Erlang performance better on single CPU(prevent context switch), but the result tells that Erlang has big latency(> 1S) under 1,000 or 5,000 connections.
* Go language is very close to Erlang, but still not good under heavy load (5,000 threads)After redo 1,000 and 5,000 tests on Nov 18
* Nginx module is the winner on 5,000 concurrent requests.
* Although there is improvement space for Go, Go has the same performance from 30-5,000 threads.
* Erlang process is impressive on large concurrent request, still as good as nginx (5,000 threads).

4. Update Log

Nov 12, change nginx.conf work_connections from 1024 to 10240
Nov 13, add runtime.GOMAXPROCS(8); to go’s code, add sysctl -p env
Nov 18, realized that ApacheBench itself is a bottleneck under 1,000 or 5,000 threads, so use 3 clients from 3 different machines to redo all tests of 1,000 and 5,000 concurrent tests.
Nov 24, use Netty with full HTTP implementation to replace Mina 2 for the Java web server. Still very fast and low latency after added HTTP handle code.

The Go GC probably accounts for much of the difference here. The Go garbage collector, by the language designers own admission, needs some improvements.

You should easily see 20k+ requests/sec on a quad core cpu with the garbage collector turned off. While running the test with the GC off is not really valid, it does give a clear indication where there is *lots* of room for improvement and does give a hint of what the language ought to be capable off given time to mature.

You could test this with:

export GOGC=off && taskset -c 1-7 ./6.out

I guess you’ll need somewhere between 1-2Gb of system RAM with the GC turned off.

Great test. Interesting how well Java stands in these tests. At the level of C performance with much higher level features.

What would really really make the picture perfect is adding the node.js hello world. (It’s on the front page of http://nodejs.org/). People talk very highly about it’s performance, but I don’t know how it would stack-up to these top speed platforms.

It probably can’t be faster than compiled Go, and even go is relatively “bad” in this company.

C, Erlang, Java and Go Web Server performance test – Tim[åŽç«¯æŠ€æœ¯] I was recommended this blog by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my difficulty. You are incredible! Thanks! your article about C, Erlang, Java and Go Web Server performance test – Tim[åŽç«¯æŠ€æœ¯]Best Regards Shane