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

  • 内存使用量少,几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

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

 

posted on 2019-07-27 01:12  cutepig  阅读(551)  评论(0编辑  收藏  举报

导航