Deno vs Node.js: Performance comparison for HTTP/2 hello world

Mayank C
Tech Tonic

--

In this article, we’ll compare Deno’s HTTP/2 server performance with Node.js’s HTTP/2 server for a simple hello world use-case. From v1.25, Deno has introduced a totally new HTTP server called flash. The flash server is still under the unstable umbrella. The flash server is limited to HTTP/1.1 only. There is no HTTP/2 support yet. Therefore, we’ll be using Deno’s current/stable HTTP/2 server for this comparison.

Test setup

Environment

The performance comparison is executed on the following environment:

  • System: MacBook M1 with 16G of memory
  • Local: The SUT and tester are on the same system
  • Deno version: 1.25.0
  • Node version: 18.8.0

Code

The following is the code for Hello world in both the runtimes. In both cases, only native APIs are used.

Node.js

const http2 = require("node:http2");
const fs = require("node:fs");
const server = http2.createSecureServer({
key: fs.readFileSync("./certs/localhost.key"),
cert: fs.readFileSync("./certs/localhost.crt"),
});
server.on("stream", (stream, headers) => {
stream.respond({
"content-type": "text/plain; charset=utf-8",
":status": 200,
});
stream.end("HTTP/2 Hello world");
});
server.listen(3000);

Deno

const options = {
hostname: "localhost",
port: 3000,
cert: Deno.readTextFileSync("./certs/localhost.crt"),
key: Deno.readTextFileSync("./certs/localhost.key"),
alpnProtocols: ["h2"],
};
const l = Deno.listenTls(options);
for await (const c of l) {
handleConn(c);
}
async function handleConn(c: Deno.Conn) {
for await (const { request, respondWith } of Deno.serveHttp(c)) {
respondWith(new Response("HTTP/2 Hello world"));
}
}

Settings

The performance test is executed in following configurations:

  • 10 concurrent connections to run a total of 10K requests
  • 25 concurrent connections to run a total of 10K requests
  • 50 concurrent connections to run a total of 10K requests

Measurements

The following measurements are recorded for each test configuration:

  • Time taken
  • Requests per second
  • Minimum
  • 1st Quartile
  • Median
  • Mean
  • 3rd Quartile
  • Maximum
  • CPU usage
  • Memory usage

Results

A total of 10K requests are executed for each test configuration.

For ease of comparison, all the results are summarized graphically. Here are the 16 graphs covering each of the above measurement:

Conclusion

Node.js’s HTTP/2 server fares marginally better than Deno’s HTTP/2 server. This gap might fill easily when Deno comes up with HTTP/2 support with new flash server.

--

--