<p>N.B. This is a noob's question about the performance of goroutines comparing to node.js event loop.</p>
<p>There are tonnes of articles that describe the difference between goroutines and threads. But I was wondering how do goroutines work comparing to libuv's (node.js) event loop? Could they be compared at all?</p>
<p>I believe, they both use the same OS mechanisms for networking and FS operations. But what about macro-/micro-tasking in libuv? Could the overhead of a goroutine be compared to them?
The other day, I saw a library where the author had been trying to implement a workflow similar to JS promises (or async / await, which I believe achieved through the same microtasking mechanisms) in Go, using goroutines.</p>
<p>At the same time, I saw some caveats that spawning a goroutine is not as cheap as spawning a promise in node.js, so the former is only great for heavy tasks like IO operations.</p>
<hr/>**评论:**<br/><br/>justinisrael: <pre><p>I don't know much about the technical details of node and it's event loop but I am pretty sure it is still single threaded. And that you have to code in a non blocking way and use promises. Go's scheduler let's you write code that blocks, since goroutines can be swapped out and multiplexed onto os threads. Also goroutines are extremely cheap to spawn (like a function stack). </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传