Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否有必要维护workerPool? #24

Closed
heydoer opened this issue Jul 23, 2021 · 4 comments · Fixed by #28
Closed

是否有必要维护workerPool? #24

heydoer opened this issue Jul 23, 2021 · 4 comments · Fixed by #28
Labels

Comments

@heydoer
Copy link

heydoer commented Jul 23, 2021

如果只是为了实现协程数量限制,仅维护逻辑上的workerCnt,直接使用go func()闭包就好了吧?还可以减少一次workerPool:Get/Put的开销。

@YangruiEmma
Copy link
Member

不是为了限制协程数量,是为了复用协程,4c测试相比直接go func() 性能更好一些。如果你的服务cores很多,用gopool可能会引入锁开销,这个在gopool有单独的优化

@YangruiEmma YangruiEmma added the wontfix This will not be worked on label Jul 26, 2021
@dyxushuai
Copy link

补充一点: worker pool 有个大的优化点是避免 goroutine 的栈扩张

@Hchenn
Copy link
Contributor

Hchenn commented Jul 26, 2021

如果只是为了实现协程数量限制,仅维护逻辑上的workerCnt,直接使用go func()闭包就好了吧?还可以减少一次workerPool:Get/Put的开销。

我来回复一下:

  1. 使用 workerPool 主要目的是复用 goroutine,减少栈扩张。在开源之前,由于依赖 netpoll 实现的框架必然存在栈扩张,所以 workerPool 是个默认项。
  2. 但开源场景下,确实可能存在没有栈扩张的场景,此时维护 workerPool 反而是负收益。因此应该支持关闭 workerPool 的开关。

TODO:

  1. 支持 DisableGopool() 来关闭 gopool

@Hchenn Hchenn added wanted and removed wontfix This will not be worked on labels Jul 26, 2021
@Hchenn Hchenn linked a pull request Aug 4, 2021 that will close this issue
@Hchenn
Copy link
Contributor

Hchenn commented Aug 4, 2021

solved: #28

@Hchenn Hchenn closed this as completed Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

4 participants