10

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.

Attila Kun
  • 2,215
  • 2
  • 23
  • 33
  • Have you tried measuring this by running one application at a time instead of both simultaneously? Does the applications still exhibit the same performance characteristics? – Ted Klein Bergman Feb 03 '21 at 22:34
  • @TedKleinBergman Yes, same behaviour. – Attila Kun Feb 03 '21 at 22:36
  • 1
    "web is slow anyway" will be my answer :p I suspect something is wrong cause this look like a big gap. – Stargateur Feb 03 '21 at 23:40
  • 1
    Rather than manually and informally doing these benchmarks using chrome/curl you should use [some CLI tools built specifically for benchmarking web servers](https://geekflare.com/web-performance-benchmark/). If the results of the benchmarks are still that Rocket & actix-web are slower than node.js you should open issues on the Rocket & actix-web Github repositories. – pretzelhammer Feb 04 '21 at 14:22
  • 1
    @pretzelhammer Thanks for the link. Couldn't reproduce it with ApacheBench; the Rust servers consistently outperformed the Node one as expected. – Attila Kun Feb 04 '21 at 21:37
  • Might be something the browser is doing. Take a look at the waterfall and timing info and see if the request is being blocked or waiting. – Alex W Feb 13 '21 at 00:12

1 Answers1

1

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.

cdecompilador
  • 178
  • 2
  • 9