Rust vs Go - Load testing webserv (>400k req/s)

martichou

Martin André

Posted on November 16, 2020

Rust vs Go - Load testing  webserv (>400k req/s)

TLDR: Go can reach 270k req/s where Rust can hit 400k req/s.

Go server

Let's go straight to buisness with a minimal server sample using httprouter.

package main

import (
    "fmt"
    "net/http"

    "github.com/julienschmidt/httprouter"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
    fmt.Fprint(w, "Welcome!")
}

func main() {
    router := httprouter.New()
    router.GET("/", Index)

    http.ListenAndServe(":8080", router)
}
Enter fullscreen mode Exit fullscreen mode

Rust

For the Rust server we'll use Actix as our framework of choice, down below is the minimal sample.

use actix_web::{web, Responder, middleware, App, HttpServer};

async fn health_check() -> impl Responder {
    "Welcome!"
}

fn routes(cfg: &mut web::ServiceConfig) {
    cfg.route("/health", web::get().to(health_check));
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let serv = HttpServer::new(move || {
        App::new()
            .wrap(middleware::Compress::default())
            .configure(routes)
    });
    serv.bind("127.0.0.1:8080")?
        .run()
        .await
}
Enter fullscreen mode Exit fullscreen mode

Benchmark

To put a big load on both our servers, we're going to use wrk.

the benchmarks are performed on a i7-8750H (6c, 12threads)

wrk -t12 -c1000 -d15s http://127.0.0.1:8080/
Enter fullscreen mode Exit fullscreen mode

Results

Rust:

Running 15s test @ http://127.0.0.1:8080/
  12 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.73ms    4.70ms  57.76ms   85.86%
    Req/Sec    33.66k     5.80k   69.35k    71.65%
  6039978 requests in 15.10s, 714.26MB read
Requests/sec: 400095.92
Transfer/sec:     47.31MB
Enter fullscreen mode Exit fullscreen mode

Go:

Running 15s test @ http://127.0.0.1:8080/
  12 threads and 1000 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.03ms    6.11ms 102.78ms   86.66%
    Req/Sec    22.81k     4.77k   53.73k    71.19%
  4087276 requests in 15.10s, 487.24MB read
Requests/sec: 270691.36
Transfer/sec:     32.27MB
Enter fullscreen mode Exit fullscreen mode

The results speak for themselves... 400.000 vs 270.000 for Rust and Go respectively.

Conclusion

While Go might be easier to write and faster to compile compared to Rust, it's still slower compared to its competitors.

If you're hesitating, let me give you this advice: use rust if you want speed, else go with Go.

Cover image from dzone.
💖 💪 🙅 🚩
martichou
Martin André

Posted on November 16, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related