Spread 4.0.0 epoll/poll Patch

Patch icon John Robinson from Vertica Systems posted a patch to the Spread-users mailing list for converting the Spread client library to use poll instead of select. I went ahead and modified the patch to enable the use of poll only when HAVE_POLL is defined instead of removing the original select code altogeher.

In addition, I modified the Spread events interface to use epoll on Linux when HAVE_EPOLL is defined. This change can improve the performance of a Spread daemon when it is serving hundreds of client connections.

To enable the poll patch to sp.c, configure with:

CFLAGS="-O2 -DHAVE_POLL"

To enable the the epoll patch to events.c configure with:

CFLAGS="-O2 -DHAVE_EPOLL"

To enable both configure with:

CFLAGS="-O2 -DHAVE_POLL -DHAVE_EPOLL"

The epoll patch processes high/medium and low priority events differently than the original code, which may have adverse consequences. For each priority level, if at least one ready event of a higher priority was processed, then only one event of the current priority level is processed. Otherwise, all ready events of the current priority level are processed.

Also, the patch's simple hash into epoll_event_map assumes file descriptor values are assigned in sequence. So use it at your own risk. It's intended only for the case where your Spread daemons are serving a lot of connections and you may benefit from avoiding select plus linear search.

Patch FileComment
spread-4.0.0-poll-epoll.patchEven though it has been tested, this patch is highly experimental and not polished final code. It's really a quick and dirty hack. Use it at your own risk. This patch is constantly evolving and may result in an all-out rewrite of the spread event handling system.