Spread 5.0.0 kqueue and epoll Patch

Patch icon This patch is a complete rewrite of a previous patch for adding epoll and poll support to Spread 4.x. It makes Spread 5.0.0 replace daemon select calls with FreeBSD kqueue or Linux epoll. POSIX poll support for the client library is standard as of Spread release 5.0.0rc2 and no longer requires a patch. The availalability of kqueue or epoll is detected automatically. Therefore, you do not have to manually define any macros. Using kqueue or epoll can improve the performance of a Spread daemon when it is serving thousands to millions of client connections.

As of Spread version 5.0.0rc2, the following changes have been incorporated into the upstream release and no longer require a patch:

Beyond adding enhanced event processing, this patch fixes a FreeBSD compilation error, installation on systems using Perl 5.22 or higher, log file initialization and writing with -l option, interface binding in loopback-only configurations, some event processing related range checks, and a premature socket descriptor close bug.

Patch FileComment
spread-5.0.0-kqueue-epoll.patch.gzAlthough this patch is well-tested and suitable for use in production environments, you should keep in mind that high/medium/low priority event processing is different from the original code. 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. This ensures lower priority events do not starve.

Revision History
Revision spread-5.0.0-1.02017-02-01 

Renamed patch after merging 5.0.0 changes, which left patch unchanged.

Revision spread-5.0.0rc2-1.12017-01-27 

Added KQEP_IS_VALID_FD_TYPE and KQEP_IS_VALID_PRIORITY macros. Changed fd_type and priority validity checks in events.c to use new macros.

Revision spread-5.0.0rc2-1.02017-01-26 

Merged Spread 5.0.0rc2 changes.

Revision spread-5.0.0rc1-1.42017-01-07 

Simplified handle_events() and eliminated potentially incorrect event caching.

Revision spread-5.0.0rc1-1.32017-01-07 

Made sp_events.h and spu_events.h match, setting MAX_FD_EVENTS to 4096.

Replaced session hash table with O(1) directly-indexed array lookup.

Revision spread-5.0.0rc1-1.22017-01-06 

Initialized uninitialized network.c globals to zero.

Removed no-op protocol functions

Moved Sess_unash_session() calls into Sess_remove_session().

Removed unused mbox parameter from Sess_validate_read_header()

Replaced instances of Sessions[ses].mbox with mbox arg in Sess_read().

Fixed bug where old data could be written to newly assigned session.

Do not execute inactive events in handle_events() loop.

Revision spread-5.0.0rc1-1.12017-01-01 

Changed epoll implementation of kqep_add_queue to only listen for EPOLLIN.

Corrected handling of priority event queues to process pending events.

Revision spread-5.0.0rc1-1.02017-12-30 

Fixed FreeBSD compilation error in daemon/ tree (INT32_MAX undefined).

Increased listen() backlog to 128.

Removed extra Alarmp calls in startup banner.

Added first draft of kqueue/epoll support based on prior 4.x patches.

Added first draft of poll client patch based on prior 4.x patches.

Fixed fixpaths to work with Perl 5.22.

Corrected priority and fd_type range checking in events.c.

Fixed daemon session log initialization sequence.

Restored functioning of loopback config file and fixed FreeBSD scope id.