Attila Kun
Attila Kun

Reputation: 2415

"Hello world" Rust webserver is slower than Node when measured from Chrome but not from curl

I created a repository with a Node.js based and a Rocket.rs based web server inside.

Consider these steps:

  1. Start the Rocket.rs server via cargo run --release
  2. Start the Node.js server via node server.js
  3. Open http://localhost:8000/ (Rocket) and http://localhost:8090/ (Node) side by side in Chrome.
  4. With the developer console open, I keep refreshing both tabs and observe that the Node tab always finishes under 5ms while the Rocket tab sometimes takes more than 300ms to finish:

enter image description here

I observed a similar thing with actix-web too, though to a lesser extent: in that case, I only get the ~300ms delay if I haven't refreshed the tab for about 5 seconds. If I keep refreshing it, then requests finish under 5ms.

Interestingly, the delay seem to not occur if I measure via curl like this and this. I get around 4ms latency with both servers.

I noticed that Rocket and actix-web do not send Keep-Alive headers in their response. Which, if I understand it correctly, shouldn't matter for HTTP 1.1 requests.

I'm using WSL 2 with Ubuntu installed. Chrome is running in the host Windows.

Could somebody please shed some light on what's going on here?

Update: Forgot to mention that I was using nightly compiler to build the rocket server (Rocket v0.4.6 seem to require it). Changing to stable and building straight from the master branch got rid of the delay. The actix-web delay is still a bit concerning though, because I used stable compiler with that one.

Upvotes: 10

Views: 1338

Answers (1)

cdecompilador
cdecompilador

Reputation: 190

Running all from windows, in node the response time is around 2-4 ms, and in rocket 1-2 ms. There is something weird happening on your enviroment.

Also tried on serving from WSL and same results.

Even on debug(rust) it takes on average +1ms more than on release, it might be some weird browser issue.

Upvotes: 1

Related Questions