Poor performance from TCPListener

Hi all,

I've been trying to write an http 1.1 server in Rust however I have found that, regardless of my approach, performance is quite poor.

I have tried several libraries and even implemented a bare-bones http server using TCPListener.

  • Hyper
  • Actix
  • May http
  • tokio::TCPListener directly
  • std::TCPListener directly
  • may::TCPListener directly

And compared it to servers written in Go and Nodejs.

Rust seems to outperform in cases where we have few clients that make a large number of requests on sockets they reuse (5 sockets with 50k requests)

A more realistic scenario is many clients making few requests, generating a large number of new socket connections (50k users making 5 requests)

Under these conditions, across all the libraries and approaches I have tested - my Rust servers have high error rates, poor latency and poor throughput.

In some cases Rust exhibits this bizarre pause/surge behavior - video here: Imgur: The magic of the Internet

I'm building with LTO and release flags and have reproduced this on several computers (all running Linux) leading me to believe that either I'm doing something wrong or that there's something fishy happening.

Can I get some advice please :pray:

1 Like

I'm a new user so I couldn't post these links in the original post

Benchmark results https://alshdavid.github.io/rust-http-benchmarks/index.html

Sources: GitHub - alshdavid/rust-http-benchmarks

Have you tried building without LTO?

Yes, same behaviour with release without LTO

I'm not seeing any weird behavior in your benchmark. The responses are HTTP 200 and the response time histogram is fairly low.

You're getting connection refused errors. That sounds like the listen socket backlog may be full, so try increasing that.

And the tiny_http example is single-threaded so it won't be comparable to others.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.