Go , Node , Apache & Nginx HTTP Performance

4,143 views
Skip to first unread message

Oleku Konko

unread,
Aug 2, 2013, 4:36:24 PM8/2/13
to golan...@googlegroups.com
Just started working with go recently but am curious about the http server performance. Ruing a simple benchmark using 



I found that Nodejs is faster than go http Implementation .. Here is my data

OS : Windows 7 64 bits 
Version : go version go1.1.1 windows/amd64

Go Code

NOTE : I was greeting AcceptEx tcp 127.0.0.1:1339: The specified network name is no longer available. so i added `w.Header().Set("Connection", "close") `

package main

import (
"fmt"
"log"
"net/http"
)

const listenAddr = "127.0.0.1:1339"

func main() {

fmt.Println("Starting Server at ",listenAddr)
http.HandleFunc("/", handler)
err := http.ListenAndServe(listenAddr, nil)
if err != nil {
log.Fatal(err)
}
}

func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Connection", "close") 
fmt.Fprint(w, "<html><body><h1>Hello, World.</h1></body></html>")
}


NodeJS (v0.10.13) Code

var http = require('http');
http.createServer(function (req, res) {
 res.writeHead(200, {'Content-Type': 'text/html'});
 res.end('<html><body><h1>Hello, World.</h1></body></html>');
}).listen(1338, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1338/');


Other servers are just basic html ....... After dispatching 500 clients in 10 sec here is the result 


GO HTTP (go1.1.1 windows/amd64)
go run gobench.go -u http://127.0.0.1:1339/hello.html -c=500 -t=10
Dispatching 500 clients
Waiting for results...

Requests:                 20689 hits
Successful requests:      18586 hits
Network failed:            2103 hits
Bad failed:                   0 hits
Requests rate:             2068 hits/sec
Test time:                   10 sec

NodeJS HTTP (v0.10.13) 
go run gobench.go -u http://127.0.0.1:1338/hello.html -c=500 -t=10
Dispatching 500 clients
Waiting for results...

Requests:                 40705 hits
Successful requests:      40334 hits
Network failed:             371 hits
Bad failed:                   0 hits
Requests rate:             4070 hits/sec
Test time:                   10 sec

Nginx HTTP (nginx/1.2.3)
go run gobench.go -u http://127.0.0.1:6060/hello.html -c=500 -t=10
Dispatching 500 clients
Waiting for results...

Requests:                 16517 hits
Successful requests:      16149 hits
Network failed:             368 hits
Bad failed:                   0 hits
Requests rate:             1651 hits/sec
Test time:                   10 sec
Recived:                  23.44 KB
Throughput:                2.34 KB/sec

Apache HTTP (Apache/2.4.3 (Win32)
go run gobench.go -u http://127.0.0.1:80/hello.html -c=500 -t=10
Dispatching 500 clients
Waiting for results...

Requests:                 15717 hits
Successful requests:      15366 hits
Network failed:             351 hits
Bad failed:                   0 hits
Requests rate:             1571 hits/sec
Test time:                   10 sec
Recived:                  23.44 KB
Throughput:                2.34 KB/sec



How can this performance  be Improved in GO ???? 



Brad Fitzpatrick

unread,
Aug 2, 2013, 7:57:14 PM8/2/13
to Oleku Konko, golang-nuts
a) why are you setting Connection: close by hand? don't do that.  If you're getting errors, your networking limits are probably too low.  You shouldn't be running benchmarks on such a machine.

b) you're not really benchmarking Node javascript. You're benchmarking's Node's HTTP stack in C against Go.  That might not be faster, but you're doing any real work.

c) Go on Windows isn't as fast for network stuff as Go on Linux.  It'll be better in Go 1.2 on Windows, but for now you should benchmark on Linux.







--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dmitry Vyukov

unread,
Aug 3, 2013, 1:56:11 AM8/3/13
to Oleku Konko, golang-nuts
Somebody just reported that Go is 41% faster than node.js on linux:
https://groups.google.com/d/msg/golang-nuts/zeLMYnjO_JA/npodNH-G8yYJ

Windows performance will improve in next releases.
Also, if you have more than 1 core, you should try benchmarking with
GOMAXPROCS=N.

Oleku Konko

unread,
Aug 3, 2013, 9:49:08 AM8/3/13
to golan...@googlegroups.com

1. Am of the assumptions that was make go slow. Is it possible to parse the same http parse in C (https://github.com/bnoordhuis/node-http-parser/tree/master/deps/http-parser) just like node rather go code.

2. I ran the test again on in Virtual Box using CentOS 6.6 and here is my result 


Node JS - 500 workers 10 sec

Dispatching 500 clients
Waiting for results...

Requests:                  6513 hits
Successful requests:       5845 hits
Network failed:             668 hits
Bad failed:                   0 hits
Requests rate:              592 hits/sec
Test time:                   11 sec
Recived:                  23.44 KB
Throughput:                2.13 KB/sec

Go - 500 workers 10 sec

Dispatching 500 clients
Waiting for results...

Requests:                 11443 hits
Successful requests:      10911 hits
Network failed:             532 hits
Bad failed:                   0 hits
Requests rate:              953 hits/sec
Test time:                   12 sec
Recived:                  23.44 KB
Throughput:                1.95 KB/sec


Conclusion : Clear Winner Go


Round 2 :


Node JS - 10000 workers 10 sec

Dispatching 10000 clients
Waiting for results...

Requests:                 16949 hits
Successful requests:       2259 hits
Network failed:           14690 hits
Bad failed:                   0 hits
Requests rate:              770 hits/sec
Test time:                   22 sec
Recived:                 105.89 KB
Throughput:                4.81 KB/sec

GO - 10000 workers 10 sec

Dispatching 10000 clients
Waiting for results...

Requests:                 16511 hits
Successful requests:       2578 hits
Network failed:           13933 hits
Bad failed:                   0 hits
Requests rate:              825 hits/sec
Test time:                   20 sec
Recived:                 113.95 KB
Throughput:                5.70 KB/sec


The Gab was suddenly closed ??? 

Round 3 :

        Node JS - 20000 workers 10 sec

Dispatching 20000 clients
Waiting for results...

Requests:                 26272 hits
Successful requests:       2725 hits
Network failed:           23547 hits
Bad failed:                   0 hits
Requests rate:              437 hits/sec
Test time:                   60 sec
Recived:                 127.73 KB
Throughput:                2.13 KB/sec

GO - 20000 workers 10 sec

Dispatching 20000 clients
Waiting for results...

Requests:                 30344 hits
Successful requests:        627 hits
Network failed:           29717 hits
Bad failed:                   0 hits
Requests rate:              337 hits/sec
Test time:                   90 sec
Recived:                  29.34 KB
Throughput:                333.87B/sec

Now Node is faster .. at this point i had to change to another benchmark tool just to be sure ... 

I had to use another tool 

Node AB 20000

This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.136 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:
Server Hostname:        192.168.1.136
Server Port:            1338

Document Path:          /hello.html
Document Length:        48 bytes

Concurrency Level:      100
Time taken for tests:   59.133 seconds
Complete requests:      20000
Failed requests:        0
Write errors:           0
Total transferred:      2960000 bytes
HTML transferred:       960000 bytes
Requests per second:    338.22 [#/sec] (mean)
Time per request:       295.667 [ms] (mean)
Time per request:       2.957 [ms] (mean, across all concurrent requests)
Transfer rate:          48.88 [Kbytes/sec] received

Connection Times (ms)
 min  mean[+/-sd] median   max
Connect:        0    1   0.4      1      32
Processing:    89  294  14.5    292     360
Waiting:       89  293  14.5    291     359
Total:         91  295  14.5    293     361

Percentage of the requests served within a certain time (ms)
 50%    293
 66%    296
 75%    299
 80%    301
 90%    308
 95%    318
 98%    331
 99%    336
100%    361 (longest request)

 
GO AB 20000

This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.136 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:
Server Hostname:        192.168.1.136
Server Port:            1339

Document Path:          /hello.html
Document Length:        48 bytes

Concurrency Level:      100
Time taken for tests:   144.231 seconds
Complete requests:      20000
Failed requests:        0
Write errors:           0
Total transferred:      3660000 bytes
HTML transferred:       960000 bytes
Requests per second:    138.67 [#/sec] (mean)
Time per request:       721.155 [ms] (mean)
Time per request:       7.212 [ms] (mean, across all concurrent requests)
Transfer rate:          24.78 [Kbytes/sec] received

Connection Times (ms)
 min  mean[+/-sd] median   max
Connect:        0    5 118.0      1    3010
Processing:    93  715 3945.4    259   57121
Waiting:       92  467 2128.4    259   48120
Total:         94  720 3978.7    260   57122

Percentage of the requests served within a certain time (ms)
 50%    260
 66%    267
 75%    271
 80%    273
 90%    280
 95%    288
 98%   3218
 99%  21098
100%  57122 (longest request)


 
Node is till faster. I also noticed 3660000 bytes Transferred ???? and after checking the headers . it still does not explain why GO had higher returned transfer 
 
 
Nodejs 

HTTP/1.1 200 OK
Content-Type: text/html
Date: Sat, 03 Aug 2013 13:38:33 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Go

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 48
Date: Sat, 03 Aug 2013 13:38:10 GMT



Is this still a windows issue even if its running on VM or its something else that needs to be looked at ?  


 

Brad Fitzpatrick

unread,
Aug 3, 2013, 5:07:25 PM8/3/13
to Oleku Konko, golang-nuts
ApacheBench (ab) is a useless piece of shit.

It's only a waste of time to use it or try to learn anything from it.



Graham Anderson

unread,
Aug 3, 2013, 6:38:38 PM8/3/13
to golan...@googlegroups.com, Brad Fitzpatrick, Oleku Konko
On Saturday 03 Aug 2013 14:07:25 Brad Fitzpatrick wrote:
> ApacheBench (ab) is a useless piece of shit.
>
> It's only a waste of time to use it or try to learn anything from it.

For this reason I've been using weighttp for a couple of years, what did you
end up using for your work on the net/http package?


Cheers the noo,
Graham

Brian Hauer

unread,
Aug 3, 2013, 6:49:15 PM8/3/13
to golan...@googlegroups.com
I'm not familiar with the first tool you're using, but seeing as it reports the number of received bytes as "Recived" (sic) it may be a work-in-progress.  For the time being, I recommend using a more established multithreaded load generator such as Wrk [1] or WeigHTTP [2].

ApacheBench is single-threaded and should be considered deprecated for this type of exercise.

Your numbers do not align with our tests [3], and while I will never say our tests are perfect, they have seen a fairly respectable amount of review from subject-matter experts.

Our data shows Go is considerably faster than node.js at web-serving fundamentals--request-routing, response rendering, and JSON serialization.  On our i7 hardware, Go achieves 193,434 requests per second versus 69,443 requests per second for node.js in Round 6 of our tests.  Even with the overhead of the full-stack Revel framework, 144,225 requests per second are produced in the JSON serialization test.

With Windows on an EC2 large instance [4], the numbers are analogous.  Go's performance is greater than 200% that of node.js: 13,312 versus 6,158.

[1] https://github.com/wg/wrk

[2] https://github.com/lighttpd/weighttp

[3] http://www.techempower.com/benchmarks/#section=data-r6&hw=i7&test=json

[4] http://www.techempower.com/benchmarks/#section=data-r6&hw=winec2&test=json

Oleku Konko

unread,
Aug 7, 2013, 3:05:58 PM8/7/13
to golan...@googlegroups.com

Good Information ... It would be nice if the versions where also included 
Reply all
Reply to author
Forward
0 new messages