I played with the code on my computer and got better performance with Go httprouter and even better results with Go fasthttp: gist.github.com/r0mdau/ac0f416d230...
Conclusion: whatever the language, take time to understand how the framework you use works and pick what fits best to you / team / project.
There is still one issue with the benchmark. FastHTTP doesn't perform any path matching against the template, hence have some benefits. I'd suggest to use raw hyper benchmark for rust instead of actix.
This code for hyper responds with exactly the same body and headers in size as fasthttp. On my computer, with LTO enabled, it performs much faster than go fasthttp.
use std::{convert::Infallible, net::SocketAddr};
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
use hyper::header::{CONTENT_TYPE, CONTENT_LENGTH, SERVER};
const RESP: &str = "Welcome!";
async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> {
let mut resp = Response::new(RESP.into());
resp
.headers_mut()
.insert(SERVER, "rusthttp".parse().unwrap());
resp
.headers_mut()
.insert(CONTENT_TYPE, "application/json".parse().unwrap());
resp
.headers_mut()
.insert(CONTENT_LENGTH, RESP.len().to_string().parse().unwrap());
Ok(resp)
}
#[tokio::main]
async fn main() {
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(handle))
});
let server = Server::bind(&addr)
.serve(make_svc);
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}
Updated my gist adding Hyper, routing in fasthttp and giving my go and rustc versions in doc. I still find fasthttp the best performer with these codes: gist.github.com/r0mdau/ac0f416d230...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I played with the code on my computer and got better performance with Go httprouter and even better results with Go fasthttp: gist.github.com/r0mdau/ac0f416d230...
Conclusion: whatever the language, take time to understand how the framework you use works and pick what fits best to you / team / project.
You had to use rust release target instead of debug
Thank you for the comment, I edited the results. 1: fasthttp, 2: actix, 3: httprouter
There is still one issue with the benchmark. FastHTTP doesn't perform any path matching against the template, hence have some benefits. I'd suggest to use raw hyper benchmark for rust instead of actix.
And please also enable the LTO in Cargo.toml
This code for hyper responds with exactly the same body and headers in size as fasthttp. On my computer, with LTO enabled, it performs much faster than go fasthttp.
fasthttp:
hyper:
Updated my gist adding Hyper, routing in fasthttp and giving my go and rustc versions in doc. I still find fasthttp the best performer with these codes: gist.github.com/r0mdau/ac0f416d230...