top of page

HTTP Servers: Deno v/s Go performance comparison



Deno, a secure runtime for TypeScript & JavaScript applications, has been around for more than a year. Deno is considered a successor of Node.js as they both have same creator (Ryan Dahl), same core technology (V8 engine), and other similar features. But Node.js isn’t the only runtime/programming language in the world. The market is full of programming languages/runtimes that claim themselves to be the best.

One of the close competitors is Go. Go’s popularity is increasing day by day. In their own words: Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Go is a statically typed, compiled programming language designed at Google. Go is syntactically similar to C, but with memory safety, garbage collection, structural typing, etc. In this article, we’ll compare Deno’s native HTTP server with Go’s native HTTP server. Being a compiled language, Go is expected to be many times faster than Deno (which is interpreted).

Let’s find out!

Code

For the comparison, we’ll use a small HTTP server that echoes the name back to the client. It reads, parses, and returns the same JSON. Here is the implementation of such an HTTP server in Deno and Go:

const listener = Deno.listen({port: 3000});
for await(const conn of listener)
    handleNewConnection(conn);
    
async function handleNewConnection(conn: Deno.Conn){
    for await(const { request, respondWith } of Deno.serveHttp(conn)){
        const reqBody = await request.json();
        if(reqBody){
            respondWith(new Response(JSON.stringify(
                {name: reqBody.name}),{
                headers: {'content-type': 'application/json'}
                }));
        }
        else respondWith(new Response(undefined,{status: 400}));
    }
}

package main 

import (
    "encoding/json"
    "net/http"
)

type ReqBody struct {
    Namestring`json:"name"`}
    
func main() {
    http.HandleFunc("/", HelloServer)
    http.ListenAndServe(":3000", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
    var reqBodyReqBody
    json.NewDecoder(r.Body).Decode(&reqBody)
    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(reqBody)
}


Both the servers parses incoming JSON body, takes the name out and returns it back in the output JSON response.


Comparison

The test environment is a MacBook Pro with core i5 and 8G of RAM. We’ve tested from single to 50 concurrent connections. We’ll see an overall comparison along with a detailed quantile analysis with graphs.

Concurrency=1

Overall:

Quantile analysis:

Deno graph:

Go graph:


For sequential requests, Go performs better than Deno

Concurrency=10

Overall:

Quantile analysis:

Deno graph:

Go graph:


For 10 concurrent connections, Deno performs at par with Go

Concurrency=25

Overall:

Quantile analysis:

Deno graph:

Go graph:


For 25 concurrent connections, Deno performs at par with Go

Concurrency=50

Overall:

Quantile analysis:

Deno graph:

Go graph:

For 50 concurrent connections, Deno performs slightly better than Go


The results are surprising! Being a compiled language, we’d expected Go to perform way better than Deno. But, to our surprise, Deno performs at par with Go!



Source: Medium; Mayank Choubey


The Tech Platform

0 comments

Recent Posts

See All

Comments


bottom of page