Deno vs Node performance: API Proxy

Mayank Choubey
Tech Tonic
Published in
4 min readDec 4, 2021

--

Introduction

This article is a part of the Deno vs Node performance series. The earlier articles are:

This time, we’ll see the performance comparison of an HTTP server that acts as an API proxy. The server sends another HTTP request to a mock server, gets a response containing a random ID, parses it, and sends the random ID in response to its caller.

Configuration

Environment

The performance comparison is executed on the following environment:

  • System: MacBook Pro with M1 processor & 16G of memory
  • Local: The SUT and tester are on the same system
  • Deno version: 1.16.4
  • Node version: 17.2.0

Test data

There is a mock API service that’s going to be used by both Deno & Node.js proxies. The mock API service generates a random UUID and sends it back to the caller. The mock API service is written in Deno. Here is the code of the mock API service:

import { listenAndServe } from "https://deno.land/std/http/mod.ts";listenAndServe(
":3001",
() =>
new Response(JSON.stringify({ randomId: crypto.randomUUID() }),{
headers: {
"content-type": "application/json",
},
}),
);

Code

Here is the code of an API proxy server that

  • Receives a request from the caller (no body in the request)
  • Sends an HTTP request to the mock server
  • Gets a response back from the mock server & parses it to get randomId
  • Sends the randomId to its caller in a JSON encoded repsonse body

The Node.js proxy is built only on native code, while the Deno proxy uses listenAndServe from Deno’s standard library. The listenAndServe API is recommended for most of the users, rather than using a combination of listen & serveHttp.

Settings

The performance test is executed in following configurations:

  • 10 concurrent connections to run a total of 3000 requests
  • 20 concurrent connections to run a total of 3000 requests
  • 30 concurrent connections to run a total of 3000 requests

Regardless of the concurrency, the total number of requests is always kept at 3000.

Measurements

The following measurements are recorded for each test configuration:

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

Results

A total of 3000 requests are executed for each test configuration. This makes it easy to compare.

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

At all levels of concurrency, Deno seems slightly faster than Node.js.

--

--