epoll_wait:maxevents [英] epoll_wait: maxevents
问题描述
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
我有点困惑的的 maxevents 的参数。比方说,我想写可处理多达10K连接的服务器。我会定义的 maxevents 的10000然后,或因某些原因是否应该更低?
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?
推荐答案
Maxevents是结构epoll_events
数组只是长度指向 *事件
。
Maxevents is just the length of the struct epoll_events
array pointed to by *events
.
如果内核具有比一些事件更在那个时候喂到你的程序就会看到,它应该不是因为你没想到,许多在那个特定_wait退还。
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.
您可能需要与此为您的程序的最佳大小进行实验。最佳的尺寸甚至可以通过建筑不同。因为你可以很容易地只设置 maxevents
来的文件(即活动的数量和规模正在轮询的文件描述符的少数
阵列因此),但所有文件,需要注意在同一时间的可能性低,所以你可能能够使用较低的 maxevents
值。
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.
这篇关于epoll_wait:maxevents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!