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

epoll_wait空转问题耗费CPU #52

Open
youzuoyong opened this issue Sep 13, 2017 · 3 comments
Open

epoll_wait空转问题耗费CPU #52

youzuoyong opened this issue Sep 13, 2017 · 3 comments

Comments

@youzuoyong
Copy link

void co_eventloop( stCoEpoll_t *ctx,pfn_co_eventloop_t pfn,void *arg )
在这个函数中调用epoll_wait定时1ms查询,进程请求量小时,会出现空转浪费CPU,可能达到1%到2%。
如果进程数量过多的话,这个CPU浪费也较明显。
建议这里考虑用户根据请求量来动态设置epoll_wait定时参数。

比如,可以根据void co_eventloop( stCoEpoll_t *ctx,pfn_co_eventloop_t pfn,void *arg )中的 pfn_co_eventloop_t pfn回调函数的返回值动态设置epoll_wait超时时间。

@LittlePeng
Copy link

LittlePeng commented Dec 18, 2017

看设计是1ms 是为了检查 timeout用的。
其实可以这样:在 loop 前计算一下所有请求中的最小超时时间min_timeout ,epoll_wait 超时指定为 min_timeout 就能解决问题

@cauhn
Copy link

cauhn commented Dec 28, 2017

一般这个timeout值都是固定的,可以根据自身情况设置。
如果在loop前计算所有请求的最小超时时间,则需要查询Epoll_t->pTimeout里最小的timeout时间,这个时间复杂度是o(n) n=60*1000,这个还是不太划算的。

@yplusplus
Copy link

比较折中的方案是检查Xms内有没有到期的定时器,有的话wait到最近到期的定时器;没有的话直接wait Xms

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

4 participants