taw
taw

Reputation: 13

Go can't handle a benchmark test (when Python & Node.js can)?

I'm trying to do a benchmark test of Go, Node.js, and Python-Flask (with Tornado).

I've been running the following for each server (several times each):

ab -c 500 -n 100000 http://127.0.0.1:5000

Node and Python are handling the load just fine, but Go is complaining:

apr_socket_recv: Connection reset by peer (104)

Here is my Node.js code:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(5000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:5000/');

Here is my Python code:

import flask
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

app = flask.Flask(__name__)

@app.route("/")
def index():
    return "Hello, world."

http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5000)
IOLoop.instance().start()

Here is my Go server:

package main

import (
   "fmt"
   "net/http"
)

func serve(w http.ResponseWriter, r *http.Request) {
   fmt.Fprintln(w, "Hello, world.")
}

func main() {
   http.HandleFunc("/", serve)
   http.ListenAndServe(":5000", nil) 
}

Is my Go source correct/optimal? I'd like to give Go a better grade than "DNF"... How is Go less reliable than Python under stress? I can only get 77% of the requests complete before the server drops off.

Upvotes: 0

Views: 556

Answers (2)

You should close request body with r.Body.Close().

Upvotes: 2

George McBay
George McBay

Reputation:

The code is probably running out of file descriptors either because they are exhaused prior to Go's gc reaping the open ones or because they are being held open by default Keep-Alive.

Boost the fd count in /etc/security/limits.conf past 1024 or whatever the default is on the OS. Or if that isn't an option, then modify the Go http server code so that it closes each web connection after the request is processed.

Upvotes: 1

Related Questions