Deno HTTP server: Native vs Oak

Mayank Choubey
Tech Tonic
4 min readMar 7, 2021

--

There are two ways to write an HTTP server in Deno:

  • Use native: Deno’s standard library comes with an HTTP server. This native HTTP library isn’t very feature-rich, but useful for basic needs.
  • Use third-party frameworks: Deno’s third-party modules have a long list of HTTP server frameworks. These frameworks are usually built over the native with additional functionality.

Deno’s native implementation is really bare-bone. There is no built-in router, body parsing, security, middlewares, logging, etc. Using a bare-bone is useful in cases when someone likes to build the basic functionality themselves.

Deno’s third-party modules pitch themselves with all the critical but missing functionality like a basic router, JSON parser (at the minimum), middlewares, plugins, etc.

The most notable of the third-party web server framework is oak. Oak is ranked highest in the list of all the available web frameworks. Oak has around 3000 stars on GitHub.

https://github.com/oakserver/oak

Oak offers great and very useful functionality, but is there a price to pay for functionality? Does oak offer the same performance as native? Is oak’s performance comparable or way worse than native? We’ll try to find the answers in this article.

In short, this article is about:

Performance comparison: Deno native HTTP server -vs- Oak HTTP server

Code

To compare the performance, we’ll use a very minimal server written using only the native code and using the oak framework. We’ve implemented a simple GET request that returns a decent-sized JSON (~400 lines if printed on console).

The native and oak code is as follows:

The JSON files are quite long, so they’re not shown here. They can be found here: https://github.com/mayankchoubey/deno-vs-nodejs/blob/master/getData.json, https://github.com/mayankchoubey/deno-vs-nodejs/blob/master/getData2.json, https://github.com/mayankchoubey/deno-vs-nodejs/blob/master/postData.json.

Both the applications have three routes:

  • GET /
  • GET /another
  • POST /

For the performance testing, the load is executed for one of the routers: GET /. The other two routes are present just to have route searching in both the apps.

Performance Results

The performance test is executed for the following parallel connections:

  • 1
  • 10
  • 25
  • 50

Detailed readings are taken for all the runs:

  • Request per second
  • Min
  • Max
  • Mean
  • Median
  • Percentile distribution from 0 to 100

Here are the results for all the runs:

Concurrency 1

Native
Oak

Concurrency 10

Native
Oak

Concurrency 25

Native
Oak

Concurrency 50

Native
Oak

Conclusion

So, what’s the conclusion? Of course, we weren’t expecting Oak to perform better than native. The reason is simple: oak is built over native, so there is no way it could perform better. But oak did perform reasonably well compared to native. On average, there is a 10% degradation in performance in using oak. But at the cost of 10% degradation, we get a lot of useful functionalities that make our life easier, our code better, cleaner, etc. The price to pay is negligible.

Our vote is to use oak.

In the follow-up article, we’ll compare oak and native’s handling of multipart/form-data.

--

--