epoll(7)的Linux手册页讨论了epoll实例的成本:
/proc interfaces
The following interfaces can be used to limit the amount of kernel
memory consumed by epoll:
/proc/sys/fs/epoll/max_user_watches (since Linux 2.6.28)
This specifies a limit on the total number of file descriptors
that a user can register across all epoll instances on the
system. The limit is per real user ID. Each registered file
descriptor costs roughly 90 bytes on a 32-bit kernel, and
roughly 160 bytes on a 64-bit kernel. Currently, the default
value for max_user_watches is 1/25 (4%) of the available low
memory, divided by the registration cost in bytes.
这仅是内存成本。我没有发现关于每个套接字有一个单独的epoll实例与每个epoll实例有多个套接字的优缺点的讨论。
这是特定于应用程序的决定吗?除了每个epoll实例160字节的开销之外,每个epoll实例选择单个套接字还有其他需要担心的问题吗?我希望套接字数以千计,所以我在牢记这一点的同时寻找答案。
这是一个多线程过程,但我想重点关注特定问题。