This is unusual of me to think of putting two technologies head-on-head but I got curious recently seeing the comparison chart from link comparing it with node and deno and wanted to try myself with deno and go which I am using at the moment but not to evaluate and choose the winner for my work but rather to satisfy my curiosity. Posting these results here so in case if you ever wanted to do one here is the summary from my experiment
GOAL: I just wanted to get only one metric out “which one serves highest number of requests per second”#
1. Golang:#
This code is straight lifted from the example at link. It’s best explained what this code does on this website but essentially we register our handler “/” using http.HandleFunc convenience function. It sets up the default router in the net/http package and takes a function as an argument. We then call the ListenAndServe function with port 8081
package main
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8082", nil)
}
2. Deno#
This code again is nothing fancy a simple example picked up from Deno’s official website link essentially here too all this is doing is starting http server on 8081 port on “/” returning 200 ok.
import { serve } from "https://deno.land/std@0.158.0/http/server.ts";
const port = 8081;
const handler = (request: Request): Response => {
return new Response(null, { status: 200 });
};
console.log(`HTTP webserver running. Access it at: http://localhost:8081/`);
await serve(handler, { port });
To test these API I am using a tool called hey built by Jaana Dogan. it’s a simple tool to stress test an endpoint and produce result detailed information in many aspects. It does give a number of requests per second which is our GOAL of this experiment.
criteria’s considered :#
- Number of requests to run: 100/10000
- Number of workers to run concurrently: 50/500
- Duration: 30 seconds
Here in the graph, it’s clear go program in these two scenarios performed at least 4–5 times faster than Deno in serving a number of requests per second. While this example is not a real-world use case where it would be much more CPU and IO intensive requirements hence these results are indicators rather than true like-to-like comparisons. Last but not least here are machine specs under which tests were run
credits:
Last but not least here is the machine specifications under which I ran this test
This post is not written in any way to critize either of the language authors work.This post is not written in any way to criticize either of the language authors’ work. lots of respect to both Go and Deno language development teams