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.
You should close request body with r.Body.Close().