My understanding is that non-blocking web servers (node.js, eventmachine, tornado) can grind to a halt if they make a call to a blocking library. Is this true for Golang as well? If one goroutine gets blocked, is another one automatically given access to the CPU, or do they have to wait for the blocked goroutine to 'yield'? If it is the former, then libraries don't need to be non-blocking, do they? I ask because I haven't seen any Redis/Mongo libraries that explicitly state that they're non-blocking.
1条回答 默认 最新
- dox90448 2013-07-24 23:34关注
My understanding is that non-blocking web servers (node.js, eventmachine, tornado) can grind to a halt if they make a call to a blocking library. Is this true for Golang as well?
No it isn't. Go routines will yield on IO or the runtime will create new OS threads as necessary.
If one goroutine gets blocked, is another one automatically given access to the CPU
Yes it is - go routines yield on any sort of IO or channel communication.
or do they have to wait for the blocked goroutine to 'yield'?
No they don't.
If it is the former, then libraries don't need to be non-blocking, do they? I ask because I haven't seen any Redis/Mongo libraries that explicitly state that they're non-blocking.
No libraries (or Go code in general) don't need to be non blocking which makes them much easier to write and maintain. This is a major plus point of Go in my opinion. The runtime does the clever bit running 1000s of go routines and you just write simple imperative code.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
- ¥50 opencv4nodejs 如何安装
- ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
- ¥15 nginx反向代理获取ip,java获取真实ip
- ¥15 eda:门禁系统设计
- ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
- ¥15 376.1电表主站通信协议下发指令全被否认问题
- ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
- ¥15 复杂网络,变滞后传递熵,FDA
- ¥20 csv格式数据集预处理及模型选择