Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

epoll_wait: maxevents

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?

like image 412
someguy Avatar asked Jun 03 '10 20:06

someguy


People also ask

What does Epoll_wait mean?

The epoll_wait() system call waits for events on the epoll(7) instance referred to by the file descriptor epfd. The buffer pointed to by events is used to return information from the ready list about file descriptors in the interest list that have some events available. Up to maxevents are returned by epoll_wait().

Why epoll is faster than select?

The main difference between epoll and select is that in select() the list of file descriptors to wait on only exists for the duration of a single select() call, and the calling task only stays on the sockets' wait queues for the duration of a single call.

What is Epoll_ctl?

DESCRIPTION top. This system call is used to add, modify, or remove entries in the interest list of the epoll(7) instance referred to by the file descriptor epfd. It requests that the operation op be performed for the target file descriptor, fd.

What is Epollhup?

EPOLLHUP is UNMASKABLE event (...). It means that after we received EOF , poll always returns immediately, making impossible poll() on write() in state CLOSE_WAIT . One solution is evident --- to set EPOLLHUP if and only if shutdown has been made in both directions.


1 Answers

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.

like image 182
nategoose Avatar answered Sep 25 '22 06:09

nategoose