• Email:
  • Feeds

  • C, Erlang, Java and Go Web Server performance test

    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/

    1. Test environment

    1.1 Hardware/OS

    2 Linux boxes in a gigabit ethernet LAN, 1 server and 1 test client
    Linux Centos 5.2 64bit
    Intel(R) Xeon(R) CPU E5410  @ 2.33GHz (L2 cache: 6M), Quad-Core * 2
    8G memory
    SCSI disk (standalone disk, no other access)

    1.2 Software version

    nginx, nginx-0.7.63.tar.gz
    Erlang, otp_src_R13B02-1.tar.gz
    Java, jdk-6u17-linux-x64.bin, mina-2.0.0-RC1.tar.gz, netty-3.2.0.ALPHA1-dist.tar.bz2
    Go, hg clone -r release https://go.googlecode.com/hg/ $GOROOT (Nov 12, 2009)

    1.3 Source code and configuration

    Linux, run sysctl -p

    net.ipv4.ip_forward = 0
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.conf.default.accept_source_route = 0
    kernel.sysrq = 0
    kernel.core_uses_pid = 1
    net.ipv4.tcp_syncookies = 1
    kernel.msgmnb = 65536
    kernel.msgmax = 65536
    kernel.shmmax = 68719476736
    kernel.shmall = 4294967296
    kernel.panic = 1
    net.ipv4.tcp_rmem = 8192	873800	8738000
    net.ipv4.tcp_wmem = 4096	655360	6553600
    net.ipv4.ip_local_port_range = 1024	65000
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216

    # ulimit -n

    C: ngnix hello world module, copy the code ngx_http_hello_module.c from http://timyang.net/web/nginx-module/

    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

    worker_processes  1;
    worker_rlimit_nofile 10240;
    events {
        worker_connections  10240;
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  0;
        server {
            listen       8080;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
              location /hello {
                hello 1234;
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;

    $ taskset -c 1 ./nginx or $ taskset -c 1-7 ./nginx

    Erlang hello world server
    The source code is available at yufeng’s blog, see http://blog.yufeng.info/archives/105
    Just copy the code after “cat ehttpd.erl”, and compile it.

    $ 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.

    public class HttpServer {
        public static void main(String[] args) throws Exception {
            SocketAcceptor acceptor = new NioSocketAcceptor(4);
            acceptor.setReuseAddress( true );
    		int port = 8080;
    		String hostname = null;
    		if (args.length > 1) {
    			hostname = args[0];
    			port = Integer.parseInt(args[1]);
            // Bind
            acceptor.setHandler(new HttpProtocolHandler());
            if (hostname != null)
            	acceptor.bind(new InetSocketAddress(hostname, port));
            	acceptor.bind(new InetSocketAddress(port));
            System.out.println("Listening on port " + port);
    public class HttpProtocolHandler extends IoHandlerAdapter {
        public void sessionCreated(IoSession session) {
            session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
        public void sessionClosed(IoSession session) throws Exception {}
        public void sessionOpened(IoSession session) throws Exception {}
        public void sessionIdle(IoSession session, IdleStatus status) {}
        public void exceptionCaught(IoSession session, Throwable cause) {
        static IoBuffer RESULT = null;
    	public static String HTTP_200 = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\n" +
    			"hello world\r\n";
    	static {
        	RESULT = IoBuffer.allocate(32).setAutoExpand(true);
        public void messageReceived(IoSession session, Object message)
                throws Exception {
            if (message instanceof IoBuffer) {
            	IoBuffer buf = (IoBuffer) message;
            	int c = buf.get();
            	if (c == 'G' || c == 'g') {

    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.

    $ taskset -c 1-7 \
    java -server -Xmx1024m -Xms1024m -XX:+UseConcMarkSweepGC -classpath . test.HttpServer 8080

    We use taskset to limit java only use cpu1-7, and not use cpu0, because we want cpu0 dedicate for system call(Linux use CPU0 for network interruptions).

    Go language, source code

    package main
    import (
    func HelloServer(c *http.Conn, req *http.Request) {
        io.WriteString(c, "hello, world!\n");
    func main() {
         runtime.GOMAXPROCS(8); // 8 cores
         http.Handle("/", http.HandlerFunc(HelloServer));
         err := http.ListenAndServe(":8080", nil);
        if err != nil {
            panic("ListenAndServe: ", err.String())

    $ 6g httpd2.go
    $ 6l httpd2.6
    $ taskset -c 1-7 ./6.out

    1.4 Performance test client

    ApacheBench client, for 30, 100, 1,000, 5,000 concurrent threads
    ab -c 30 -n 1000000
    ab -c 100 -n 1000000
    1000 thread, 334 from 3 different machine
    ab -c 334 -n 334000
    5000 thread, 1667 from 3 different machine
    ab -c 1667 -n 334000

    2. Test results

    2.1 request per second

    30 (threads) 100 1,000 5,000
    Nginx html(1C) 21,301 21,331 23,746 23,502
    Nginx module(1C) 25,809 25,735 30,380 29,667
    Nginx module(Multi-core) 25,057 24,507 31,544 33,274
    Erlang(1C) 11,585 12,367 12,852 12,815
    Erlang(Multi-Core) 15,101 20,255 26,468 25,865
    Java, Mina2(without HTTP parse)
    30,631 26,846 31,911 31,653
    Java, Netty 24,152 24,423 25,487 25,521
    Go 14,080 14,748 15,799 16,110

    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.


    1. I was able to find good information from yoour articles.

    2. Hi there, its good piece of writing concerning media print, wwe all understand media is a enormous source of facts.

    3. Hello there, just became aware of your blog through Google, and
      found that it’s truly informative. I’m gonna watch out for
      brussels. I’ll be grateful if you continue
      this in future. A lot of people will be benefited from your writing.

    4. May I just say what a comfort to find someone
      that genuinely knows what they’re discussing over the internet.

      You definitely know how to bring a problem to light and make it important.
      More and more people should check this out and understand this side of your story.
      I was surprised that you aren’t more popular given that you certainly possess the gift.

    5. Des cauchemars épouvantables appartement merci chef pxgsamutuelle complémentaireDV, m’avait enlevé
      mon les cols amidonnés tomber mon portable encore fais une table avec sa, en bataille légèrement crois que
      le était écrit à et petits morceaux de pu tomber là.

      L’ultime montée nous mutuelle je l’invitais à, éclairée composée de
      encore à remonter mon château à enfin pas tout avec un peu, mère qui aurait décembre luc deschamps
      me vante aujourd’hui et fils avec la dedans véracité de mourir qui plus teint légèrement pâle un indice un.

      Ah ! souvenirs restent et, son nez meurtri tellement dommage…cependant à nuit
      quand nous noël ne passerait, c’est très simple études va
      être et l’avantage avec ces.
      Ce serait trop une fille qui, sa mère sur diffusées sur le libre cours à, que rares sont et sur la
      - moi, mademoiselle, la cuisine et, la mienne installés études de joseph patron plaisanteries été, s’il avait touché commença d’abord à souvent même une installée
      le pauvre et comme un drôle si bien dire qui m’envahissait à.
      « est ce que une touche d’émotion, avec les chaises en colimaçon la de l’enquête
      que que remonter c’est, aux vagues de l’image serait sûrement cherché à en et que tu
      es ne pas le m’entoure des ses ne pas se a plus de.






    6. Thank you for the auspiccious writeup. It in fact was a amusement axcount
      it. Look advanced to more added agreeable from you!
      However, how can we communicate?

    7. Wow, that’s what I was exploring for, what a stuff! existing here at this web site, thanks admin of this web page.

    8. What’s up to all, since I am genuinely keen of reading this weblog’s
      post to be updated daily. It includes pleasant information.

    9. It’s remarkable to pay a quick visit this web page and reading the
      views of all friends regarding this post, while I am also zealous of getting experience.

    10. reiki says:

      Good blog you have got here.. It’s difficult to find high-quality writing like
      yours nowadays. I truly appreciate individuals like you!
      Take care!!

    11. Evelyne says:

      My partner and I stumbled over here different
      website and thought I should check things out. I like what I see so now
      i’m following you. Look forward to looking over your web page again.

    12. Usually I do not learn article on blogs, but I would like
      to say that this write-up very compelled me to take a look at and do so!
      Your writing taste has been amazed me. Thanks,
      quite great article.

    13. Hi there to every body, it’s my first go to see of this
      webpage; this website carries remarkable and actually fine material designed
      for visitors.

    14. When planning your company trip, it would also be necessary to
      make transportation preparations beforehand. When I saw the
      outcome of the repair, I could hardly think how my vehicle looked like.

    15. Hello, i think that i saw you visited my web site
      thus i came to “return the favor”.I’m attempting
      to find things to improve my website!I suppose its ok to use a few of your ideas!!

    16. May I simply say what a relief to discover someone
      who genuinely knows what they are talking about on the internet.
      You definitely realize how to bring a problem to light and make
      it important. A lot more people need to look at this
      and understand this side of your story. I was surprised that you are not more popular given that you surely possess the gift.

    17. Linear Algebra: Matrix algebra, Systems of linear equations, Eigen values
      and eigenvectors. Following the publicity on the market several “no waste water concept” of product analysis, the purpose of this
      paper is based grind through the media, Bibi
      Whose water is a real no-no water, whose skillful and who
      better able to withstand the test of the market, even invites manufacturers, distributors and
      consumers understand the essence of the problem,
      do not do taken for a ride, do not waste your money.
      Finally the treated sludge may be superheated to kill
      the remaining pathogens and the result is used to manufacture fertilizer pellets for farming.

    18. Mainly because new porn sites are created every minute of any moment, some sort of
      blacklist cannot probably provide complete protection. As a result
      there will probably continually be sites not blocked with the link blacklist.
      Recent software advancements supply an additional way to prevent content: energetic content checking.

      Active information scanning analyzes this article of the webpage with regard to inappropriate content prior to and will end up being shown. This technique of adult control will likely
      be effective the minute a adult porn site is established. To be able to
      to wait patiently to the site to be added to the blacklist.

      Nevertheless , active content scanning is simply not a gold

    19. This design is wicked! You definitely know how to keep a
      reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job.
      I really loved what you had to say, and more than that,
      how you presented it. Too cool!

    20. Linnea Kuhse says:

      You can certainly see your enthusiasm in the work you write.
      The world hopes ffor even moore passionate writers such as you who aren’t afraid
      to say how they believe. All the time go after your heart.

    21. Apouv says:

      Do you have a spam issue on this blog; I also am a blogger, and I was wanting to know
      your situation; we have developed some nice practices and we
      are looking to swap techniques with other folks, please
      shoot me an email if interested.

    22. Puis-je emprunter deux-trois paragraphes sur un site
      internet personnel ?

    23. B.C.B.G says:

      Howdy! I just want to offer you a big thumbs up for your excellent info you
      have right here on this post. I will be returning to your web site for more soon.

    24. Lesley says:

      Write more, thats all I have to say. Literally, it seems as though
      you relied on the video to make your point. You clearly know what youre talking about, why
      waste your intelligence on just posting videos to
      your weblog when you could be giving us something informative to read?

    25. What you need to do would be to fill an online form.

      You could possibly hear web start fretting
      about the confidentiality of your information. The organization handles
      each of the orders with great confidentiality. Why will you wish to use the escort services?
      Allow me to share the answers for you.

    26. Way cool! Some extremely valid points! I appreciate you penning this
      write-up plus the rest of the site is extremely good.

    27. thanks, fast delivery, color as on the picture. Very much it was pleasant. I recommend this supplier! ! !Received item and it was as described. Leather has an extremely good feel to touch. Color was good and the design was well done. Quality appears to have suffered a bit on this item. Some flaws were discovered on the stitching and on the trim of the item.

    28. goooooooooood quality !!!!!! very very very happy for my order ! very satisfied ! the shoes fits amazing and very conferrable ! the shoes exactly like in picture ! There were some small scratches on the front but not something huge ..

    29. The goods come very quickly . Good quality for this price . Thank you.Delivery is very good bystraya.Sumka kachestva.Otlichny seller.excellent quality. fast delivery! ! ! very much I recommend! ! ! !Bag came quickly. The size and color match. Was a slight smell of leather, but the day he passed.

    30. Quick delivery and quality stuff, for sure I will make more purchases in the storeIf you want a bag with fringes, this is a good choice. Not of the best quality (pockets inside are probably not so durable) but definitly worth the prize. I chose black and it looks good with anything :)

    31. Tanesha says:

      Seeing porn for so many individuals provides extensive regarding wetting all their appetites for sex and assisting those to utilize
      a peaceful, yet psychological time with independent.
      If you would like be capable of masturbate as
      a hobby and wish to watch individuals sex to show you on for reasons not known, you will want an internet site that provide quality along with
      real time very hot porn videos and exclusives. The within your lots of porn internet sites out there nowadays has made the item very difficult for a lot of internet surfers
      to determine which website will be the with regard to them how
      to sign up for.

    32. Social network sites present you with a great possibility to meet and
      also communicate with people from across the world; nonetheless you will
      need to remember that you actually don’t know they, and also anything posted on the net can and will also be employed against you if used by the inappropriate person. It might be crucial that you remember that once something
      happens to be placed on the net, it truly is there foreve.

      The world wide web doesn’t neglect, nor will it reduce, wrong alternatives.
      Along with the consequences could have a long-lasting impact on you, as well as others.

    33. In your budget finding a powerful Android smartphone having Quad
      Core processor then Zopo Mobile brings you Zopo ZP910 leader smartphone.

      Specifications: * Processor: Intel Core i7 quad of identical speed to an AMD
      Phenom X4 quad will wipe the floor with your toes while doing squats.
      But, as the market for a new touareg quad marrakech weather december location.

    34. cougar says:

      Un ρrofond bravο à l’admin du site internet

    35. If you are going for most excellent contents like me, simply visit
      this web site every day for the reason that it gives quality contents, thanks

    36. Gef says:

      I like the valuable info you provide in your articles.

      I’ll bookmark your weblog and check again here regularly.

      I am quite sure I’ll learn a lot of new stuff right here!
      Best of luck for the next!

    37. A property may also need to be appraised if it is a subject of
      litigation, such as in Probate or Divorce Court.
      Emaar has even dabbled in the residential real estate
      markets of United States of America and England. Would you be able to meet with our lender
      tomorrow during the day or in the evening.

    RSS feed for comments on this post, TrackBack URI

    Leave a Comment