epoll_wait: maxevents

China☆狼群 提交于 2019-12-05 18:14:47

问题


int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);

I'm a little confused about the maxevents parameter. Let's say I want to write a server that can handle up to 10k connections. Would I define maxevents as 10000 then, or should it be be lower for some reason?


回答1:


Maxevents is just the length of the struct epoll_events array pointed to by *events.

If the kernel has more than that number of events to feed to your program at that time it will see that it should not because you aren't expecting that many to be returned in that particular _wait.

You will probably need to experiment with the optimal size of this for your program. The optimal size may even differ by architecture. For small numbers of file descriptors being polled you can quite easily just set maxevents to the number of files (and size the events array accordingly), but the likelihood of all files needing attention at the same time is low, so you would probably be able to use a lower maxevents value.



来源:https://stackoverflow.com/questions/2969425/epoll-wait-maxevents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!