async-await vs goroutines + channel, which is better performence for handling many WebSocket connection?


most people think that goroutine is better than async/await. because goroutines combine parallel and concurrent. but what I know is that node js itself is not really a single thread. because every i/o process is delegated to libuv. and libuv itself is multi-threaded.

so which is better between async/await in node.js and goroutine, in this case, is to handle a million WebSocket connection?


To answer this quest properly we need to make a benchmark test, to get the real results and compare them, but we can thinking a little about it.

First of all, libuv has a pool of threads to deal with the async operation but is not an infinity pool (if I am not wrong by default the libuv has 4 threads) and each thread can handle one async operation per time.

On the other hand, Golang uses the "green thread model", where each goroutine is an isolated process and handles one operation per time. Theoretically, you can spawn how many goroutines you want per OS Thread.

Each runtime has pros e cons and maybe we can figure out which runtime is better, but I think the real problem is "how will we manage the horizontal scalability of our application". We need to choose the runtime based on our deployment strategy and our team’s knologment.

Answered By – ralvescosta

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.