协程 相对于 多线程的主要优势?

  • 内存使用量少,几k vs 至少1MB
  • 可增长的分段堆栈
  • 启动时间比线程快
  • 在共享数据结构时避免使用互斥锁

 

https://medium.com/@kevalpatel2106/why-should-you-learn-go-f607681fad65

  •  非常快速的上下文切换
  • 没有并发问题
  • 选择您的调度程序
  • 性能
  • Creation (thread: 18 microseconds, fiber: 0.45 microseconds)

https://medium.com/software-design/boost-fiber-in-your-code-9dcdda70ca00

Table 1.1. time per actor/erlang process/goroutine (other languages) (average over 1,000,000)

Haskell | stack-1.4.0

Go | go1.8

Erlang | erts-8.3

0.05 µs - 0.06 µs

0.45 µs - 0.52 µs

0.63 µs - 0.73 µs

Table 1.2. time per thread (average over *10,000* - unable to spawn 1,000,000 threads)

pthread

std::thread

54 µs - 73 µs

52 µs - 73 µs

 

Table 1.3. time per fiber (average over 1.000.000)

fiber (16C/32T, work stealing, tcmalloc)

fiber (1C/1T, round robin, tcmalloc)

0.05 µs - 0.11 µs

1.69 µs - 1.79 µs

 

https://www.boost.org/doc/libs/1_64_0/libs/fiber/doc/html/fiber/performance.html

其他:我猜的

  • cache miss机会少? stackless有机会少,stackful由于要求换堆栈寄存器,未必
  • 由于不需要进入kernel,减少context switch

 

线程池的主要优势?

  • 内存使用量少

 

 tbb flow graph how to schedule tasks

from https://software.intel.com/en-us/node/506295

调度程序采用称为工作窃取的技术

 

转载于:https://www.cnblogs.com/cutepig/p/11253625.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值