← back

Benchmarking different http framework from NodeJs, C, Go and Rust.

To Benchmark i have used ab (Apache Bench) which is an http benchmarking tools from Apache.

Configuration

I have used

ab -n 100000 -c 1 http://127.0.0.1:3000/

command which means sending 100000 (1 Lakh) request with 1 concurrent connections.

This config have given most differentiable results.

Express.js

Project setup:

Need express.js package from npm

Express.js folder structure

Code:

const express = require("express");
 
const app = express();
 
app.get("/", (req, res) => {
	res.send("ABCD");
})
 
app.listen(3000);

Result: 2543.58 Requests / Second

Fastify.js

Fastify is the fastest http framework for nodejs.

Project setup:

Need fastify package from npm

Fastify.js folder structure

Code:

const fastify = require('fastify')({
    logger: false
});
 
fastify.get('/', (request, reply) => {
  reply.send("ABCD");
})
 
fastify.listen({ port: 3001 })

Result: 5805.55 Requests / Second

GoLang's Build In net/http

Project setup:

No need to install any third party lib or package.

Go lang folder structure

Code:

package main
 
import (
    "net/http"
)
 
func main(){
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("ABCD"))
        return 
    })
 
    http.ListenAndServe(":3002", nil)
}

Result: 6401.89 Requests / Second

Rust

Project setup:

Need axum and tokio package from crats.io

Rust lang folder structure
use axum::{
    routing::get,
    Router
};
 
#[tokio::main]
async fn main()  {
    let app = Router::new()
        .route("/", get(root));
 
    let ln = tokio::net::TcpListener::bind("127.0.0.1:3003").await.unwrap();
    axum::serve(ln, app).await.unwrap()
}
 
async fn root() -> &'static str {
    "ABCD"
}

Result without --release flag: 3311.86 Requests / Second

Result with --release flag: 7882.94 Requests / Second

i.e building with this cargo build --release

Changing Configuration

Now i am using

ab -n 100000 -c 100 http://127.0.0.1:3001/

This means total of 100000 (1 Lakh) request with 100 concurrent connections.

And the results are:

  • Express.js performs 3235.46 requests / second

  • Fastify.js performs 7443.41 requests / second

  • Go performs 11,297.47 requests/ second

  • Rust Without --release flag performs 10,805.90 requests / second

  • Rust With --release flag performs 12,687.14 requests / second

On 1000 concurrent connections.

ab -n 100000 -c 1000 http://127.0.0.1:3003/
  • Express.js and Fastify.js (both for node.js) get crashed.

  • Go performs 11,252.25 requests / second

  • Rust performs 12,189.86 requests / second

Todo...

I have done the benchmarking on very low-end Virtual Machine.

To do the same benchmakring on very - ultra - high end Virtual Machine.