Created
April 7, 2019 08:28
-
-
Save Wang-Kai/4dae63dbecd6905cd1a9b080cc5024ca to your computer and use it in GitHub Desktop.
Revisions
-
Wang-Kai created this gist
Apr 7, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ 在一本书上看到一句话: > 用多进程实现分布式和负载均衡,减轻单进程垃圾回收压力;用多线程(LWP)抢夺更多的处理器资源;用 coroutine 来提高处理器时间碎片利用率。 这句话是我在《Go 语言笔记》上看到的,《操作系统》我读的不深,所以分享下我的理解,希望纠正和补充。 对于存在 GC 的语言来讲,这个进程不仅要处理业务逻辑,还要在背后做空闲资源的回收和释放。单 CPU 的计算能力有限,所以通过将任务分发到不同的进程(可能是 CPU 物理上都是分开的)上,可以减轻进程压力。 如果一个进程中有多个用户态线程,假使某个线程陷入 I/O 阻塞,该进程也会快速的切到其他线程,继续执行计算任务,而不是因为某个线程阻塞而该进程被操作系统换出运行态。 coroutine 由 runtime 来调度给不同的线程来执行,在一个线程上切换 coroutine 比 在进程层面上切换线程的开销要小很多,所以能提高处理的利用率。