[英]maxevents parameter in epoll_wait() and the events array size
In epoll usage, it is usually like the following: 在epoll使用中,它通常如下所示:
struct epoll_event ev,events[20];
epfd=epoll_create(256);
。。。
nfds=epoll_wait(epfd,events,40,500);
Some articles are saying that the maxevents
parameter in epoll_wait
(namely the 40
in epoll_wait(epfd,events,40,500);
) should not exceed the size parameter in epoll_create
(namely the 256
). 有些文章说,
maxevents
参数epoll_wait
(即40
在epoll_wait(epfd,events,40,500);
)不应超过大小参数epoll_create
(即256
)。
I think the maxevents
parameter should not exceed 20
in ev, events[20]
, because events can only be registered to 20 events elements; 我认为
maxevents
参数在ev, events[20]
不应超过20
,因为事件只能注册到20个事件元素; otherwise, if there are 40 sockets which are active, then what will happen? 否则,如果有40个插座是活动的,那会发生什么?
BTW, if I register more than 20 sockets and there are more than 20 active events(sockets), but the events array events[20]
has only 20 events, what will happen? 顺便说一句,如果我注册超过20个套接字并且有超过20个活动事件(套接字),但事件数组
events[20]
只有20个事件,会发生什么?
At any single call of epoll_wait
you'll at most receive as many events as you have room for, but of course events don't get lost if there are more than that queued up -- you'll simply get them at a later call. 在
epoll_wait
任何一次调用中,你最多epoll_wait
获得尽可能多的事件,但当然,如果有多个事件排队,事件也不会丢失 - 你只需在以后的电话中获取它们。 Since you'll be calling epoll_wait
in a loop anyway, that shouldn't be an issue at all. 既然你无论如何
epoll_wait
在一个循环中调用epoll_wait
,那根本不应该是一个问题。
The one interesting consideration I can think of is when you have multiple threads read from the same epoll-fd concurrently. 我能想到的一个有趣的考虑因素是你同时从同一个epoll-fd读取多个线程。 In that case the size of your event array determines how many events get handled by a single thread (ie a smaller number might give you greater parallelism).
在这种情况下,事件数组的大小决定了单个线程处理的事件数量(即较小的数字可能会提供更大的并行度)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.