This is a lot of work which probably is not needed.

I don't think you understand select and the supporting fd_set type.

I'll include the NOTES from Freebsd on the select(2) man page....

NOTES
     The default size of FD_SETSIZE is currently 1024.  In order to
     accommodate programs which might potentially use a larger number of open      files with select(), it is possible to increase this size by having the
     program define FD_SETSIZE before the inclusion of any header which
     includes <sys/types.h>.

     If nfds is greater than the number of open files, select() is not
     guaranteed to examine the unused file descriptors.  For historical
     reasons, select() will always examine the first 256 descriptors.

Another solution to this is to have code which does not use fd_set but instead uses its own method of building and using bit arrays. I have done this in my professional development.

Jeff Anton

PS: For those of you who do not know me, I was the first lead programmer on the Postgres project at U.C.Berkeley a very long time ago. You can blame me (or praise me) for many of the internals such as memory contexts.


On 10/25/26 23:41, Roman Khapov wrote:
Hi hackers!

While working on [1] I run performance tests on different environments,
including laptop with macOS. pgbench is usually chosen for this,
but on one of the last runs I discovered that it uses select() on macOS (which 
lacks
the ppoll() syscall), which caps the max amount of clients at 1024 (FD_SETSIZE).

This can be fixed with new implementation of socket_set based on kqueue().
The only wrinkle is fact that select() and ppoll() is stateless, while kqueue() 
is not
(registration persists in kernel across kevent() calls), so 
wait_on_socket_set() must be
written in harder way than other implementations:
- disable stale registrations: EV_DISABLE for every fd to drain error for 
closed fds
- enable current set with EV_ENABLE, call kevent()
- report results (save flags in socket_set->input_ready) + preserving the set 
for the next iteration

POC-patch attached, any feedback would be appreciated!

[1] - https://github.com/yandex/odyssey

--
Best regards,
Roman Khapov


Reply via email to