In this test, I made two servers, one with node (express) and the other with golang (gin) and tested out their performance on handling requests. I used Apache bench for this and logged the results into a log file at the end. Let me give you a glimpse of the servers made to test out.
Make a directory named nodejs and yarn init inside it, this will spit out a package.json file which will contain all the dependencies of the app. Next create a folder to collect all the logs we are going to do afterwards. I made a folder named express/logs to store all the logs. Then I gave sufficient permissions to the log files to be able to store logs inside it (just a UNIX thing). Then I wrote a basis javascript file named express.js which will act as the server in our case.
Pretty much everything goes the same in case of Golang. I created a folder golang and go mod init inside it. This will create a go.mod file to store all the dependencies and their versions for the project. A github.com remote url is given so as to be able to convert to a module and be able to store it on github (just in case). This will enable other people to be able to download our code as a module and use it in their codebases. Then as earlier, we created log files and gave them relevant UNIX permissions. Then I wrote a basis go file named gin.go which will act as the server in our case.
Since, golang is a compiled language, I compiled it to a binary by running go build golang/gin.go. At the end, I did three tests, and the load/concurrency goes as follows. Also, One may argue that Nodejs is single threaded and hence cannot use all the available resources of the host machine, so just for those guys, I tested dedicated using PM2 on cluster mode at max number of connections.
In each of the cases above, Golang simply rocks in each of the parameters above. The main parameters of our concern are :
Failed Requests (Most important): Even in the test 1 category, Nodejs fails to deliver a good performance required for a server side application.
Number of bytes transferred (should be lesser as both the servers are sending the exact same thing)
Requests per second (determines the actual concurrency throughput): Should be maximum
Time per request (Golang has an edge here because it is compiled and nodejs (javascript) is interpreted): Should me minimum. Responses must be as quick as possible so as to provide a good user experience
Transfer rate (how much the server is capable of): Even if both the test is done on the same network and with same bandwidth, Golang provides faster delivery (not by a very high margin)
Waiting time (ms, Average time to wait before handling the request):Requests need to be fulfilled as quick as possible, waiting time must be less as a whole