Skip to content

Instantly share code, notes, and snippets.

@eldritchideen
Last active April 22, 2017 23:41
Show Gist options
  • Save eldritchideen/e2d662e4ff08989bbeb412a43eb26a19 to your computer and use it in GitHub Desktop.
Save eldritchideen/e2d662e4ff08989bbeb412a43eb26a19 to your computer and use it in GitHub Desktop.
HTTP Server Micro-Benchmarks

HTTP Server Micro-Benchmarks

Here are the results of testing returning a small text string from a HTTP request implemented in various languages all, tested under the same conditions. The command used to test the server implementations was:

wrk -c 40 -d 60s -t 2 --latency http://localhost:3000

Python3

This test used the new async support in python 3.5.

import asyncio
from aiohttp import web

async def handle(req):
    return web.Response(body=b"Hello")

app = web.Application()
app.router.add_route('GET', '/', handle)

web.run_app(app)

The results were about 2,300 Requests/sec.

Javascript

Using the express framework and node 6.

const express = require('express');
const app = express();

app.get('/', function (req, res) {
  res.send('Hello');
});

app.listen(3000, function () {
  console.log('listening on port 3000!');
});

This resulted in 7,200 Requests/sec.

Elixir

Using the Plug library and Cowboy as the HTTP server.

defmodule SimplePlug do
  import Plug.Conn

  def init(options) do
    options
  end

  def call(conn, _opts) do
    conn
    |> put_resp_content_type("text/plain")
    |> send_resp(200, "Hello")
  end
end

Started the plug using:

{:ok, _} = Plug.Adapters.Cowboy.http SimplePlug, []

Got about 25,000 Requests/sec.

Java

Using the Spark framework with Jetty HTTP server.

import static spark.Spark.*;

public class Main {
    public static void main(String[] args) {
        get("/", (req, res) -> "Hello");
    }
}

Resulted in about 35,000 Requests/sec.

Go

Using the built in http package in Go.

package main

import (
	"io"
	"net/http"
)

func handler(writer http.ResponseWriter, request *http.Request) {
	io.WriteString(writer, "Hello")
}

func main() {
	http.HandleFunc("/", handler)
	http.ListenAndServe(":8080", nil)
}

This resulted in about 51,000 Requests/sec.

Rust

Using Rust and the Hyper crate to serve HTTP.

extern crate hyper;

use hyper::server::{Request, Response};

static PHRASE: &'static [u8] = b"Hello";

fn hello(_: Request, res: Response) {
    res.send(PHRASE).unwrap();
}

fn main() {
    let _listening = hyper::Server::http("127.0.0.1:3000").unwrap()
        .handle(hello);
    println!("Listening on http://127.0.0.1:3000");
}

Served up about 50,000 Requests/sec/

Haskell

Using the Scotty web framework.

{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Data.Monoid ()

main :: IO ()
main = scotty 3000 $
  get "/" $ text "hello"

Managed the best result at 31,000 Requests/sec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment