DEV Community

Cover image for ⚡️Golang VS Node.js⚡️ - CSV Data Export
rizkypujiraharja
rizkypujiraharja

Posted on • Updated on

⚡️Golang VS Node.js⚡️ - CSV Data Export

Prologue

Three months ago, I encountered a challenge while exporting CSV data using PHP. The problem revolves around long duration and large memory consumption. Therefore, I started looking for alternative solutions to overcome this problem. This prompted me to conduct an experiment comparing data export speed using Node.js and Golang. I have created a project repository for this, which you can find at https://github.com/rizkypujiraharja/benchmark-export-data-to-csv

When it comes to exporting data in CSV format, efficiency and speed are key factors to consider. In this article, we will delve into how each programming language can be employed to accomplish this task and how to measure and compare their performance. By understanding the differences in approaches and performance outcomes among these two languages, you will be better equipped to make informed decisions when selecting the right tool for your next CSV data export project.

Here we go!!

In this testing, I use a server with specifications of 8 GB RAM / 8 vCPU per day on Railway. I have created a REST API to export data to CSV, which retrieves 50,000 records from MongoDB database.
To minimize memory usage and enhance efficiency, I fetched the data in chunks of 10,000 rows per query. This approach enables more efficient processing of large datasets, as data does not need to be fully loaded into memory all at once.

I will conduct two rounds of testing: the first one will be manual testing, and the second will involve load testing using https://github.com/tsenart/vegeta.
I hope this explanation helps you better understand the context of this testing.

#Manual Testing

Golang took 0.332430 seconds, while Node.js took 0.844 seconds. This means Golang is 3 times faster than Node.js.
Golang manual testNode.js manual test

#Load Testing

The testing was conducted by sending 5 concurrent requests every second for a duration of 10 seconds.

Min Max Mean CPU Usage Memory Usage
Golang 530.717ms 984.27ms 572.301ms 0.2vCPU 317MB
Node.js 6.245s 18.586s 22.872s 0.7vCPU 1.03GB

Vegeta Result
Vegeta result golangVegeta result nodejs

Usage Resource
Resource test golangResource test nodejs

It is evident that when testing concurrent requests, Golang outperforms Node.js.

Top comments (2)

Collapse
 
renodesper profile image
Boy Sandy G. A.

Interesting. Have you checked which one burdens the server more than the other? You're only talking about the resource where the Go and NodeJS are running. I'm curious which one took less resources.

Collapse
 
rizkypujiraharja profile image
rizkypujiraharja

Maybe you miss it, I have written in the results of the load testing in the table.

Golang spent 0.2VCPU and 317MB of memory, while node.js 0.7VCPU and 1.03GB