I created a repository with a Node.js based and a Rocket.rs based web server inside.
Consider these steps:
- Start the Rocket.rs server via
cargo run --release
- Start the Node.js server via
node server.js
- Open http://localhost:8000/ (Rocket) and http://localhost:8090/ (Node) side by side in Chrome.
- 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:
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.