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

无法超过两根工作线程同时工作 #39

Closed
hlouis opened this issue Sep 17, 2013 · 5 comments
Closed

无法超过两根工作线程同时工作 #39

hlouis opened this issue Sep 17, 2013 · 5 comments

Comments

@hlouis
Copy link
Contributor

hlouis commented Sep 17, 2013

由于在 shield_start 中的 Wakeup 函数 busy 参数只会被传入 0 或者 1

导致当 sleep 线程的个数小于总工作线程数 2 的时候,就不会再有线程被唤醒,这应该是一个手误,不过不太理解设计这个wakeup调度的初衷。

cloudwu added a commit that referenced this issue Sep 17, 2013
@cloudwu
Copy link
Owner

cloudwu commented Sep 17, 2013

谢谢, 已修正.

这样做是因为在 IO 负荷大, 但业务简单的压力测试中, 我发现频繁 pthread_cond_signal (有系统调用)有比较大的开销.

skynet 可以在多于 1 的工作线程下正常运作. 所以不用急着唤醒 sleep 的工作线程 (只要有一个在工作就够了). 在网游的环境下, 大多数情况下都没有工作线程 sleep, 所以就无所谓唤醒. 只有在整个服务器闲置的情况下才会因为 IO 消息把服务器重新热起来. 如果 IO 消息很少, 那么唤醒多个也没有太多意义.

现在的修改是每 0.25 秒 (慢热), 由 timer 去尝试唤醒一次; IO 模块保留原来的设计, 只有在全部工作线程都 sleep 的时候才发送 pthread_cond_signal .

@cloudwu cloudwu closed this as completed Sep 17, 2013
@hlouis
Copy link
Contributor Author

hlouis commented Sep 17, 2013

多谢说明,不过还是有一点不太理解:

假设我们的系统中有四个Service进行繁忙的周期性的CPU操作,他们都通过Skynet的Timer来驱动自己

如果按照之前的wakeup的调度,就算mq中有四个service有timer消息,也只能唤醒两根工作线程来进行工作,看起来有些不合理。

@cloudwu
Copy link
Owner

cloudwu commented Sep 17, 2013

如果目前热起来的工作线程来不及干完 timer 交给它的事情的话, 那么 timer thread 里的 wakeup 就会唤醒新的工作线程了. 否则, 一两个工作线程也能及时处理掉四个 service 的 timer 事件.

之前那个的确是 bug, 我已经改了. ( timer thread 里应该是至少只要有一个工作线程在 sleep 就唤醒它, 而不是至多一个在 sleep)

@cloudwu cloudwu reopened this Sep 17, 2013
@cloudwu cloudwu closed this as completed Sep 17, 2013
cloudwu added a commit that referenced this issue Sep 17, 2013
@cloudwu
Copy link
Owner

cloudwu commented Sep 17, 2013

我原本是想在 timer thread 里写: 如果有一个 worker thread 在 sleep 就发一个 signal, 结果想岔了, 就传了个 1, 变成了有一个没在 sleep 才发 signal .

@hlouis
Copy link
Contributor Author

hlouis commented Sep 17, 2013

呵呵,了解,多谢说明

On Sep 17, 2013, at 11:22 AM, 云风 notifications@github.com wrote:

我原本是想在 timer thread 里写: 如果有一个 worker thread 在 sleep 就发一个 signal, 结果想岔了, 就传了个 1, 变成了有一个没在 sleep 才发 signal .


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants