The cluster module share server ports by accepting new connections in the primary process and distributing them to worker processes.
With SO_REUSEPORT, sockets will be distributed by kernel instead, and which should be more performant especially for scenario of having a lot of short-lived connections.
For example, the arrow in the image below shows cpu usage of a PM2 primary process which we found in our environment.
Note that SO_REUSEPORT might behave much differently across operating systems. See this post for more information.
node-unix-socket
node-unix-socketallows you to use some nonblocking unix sockets that are currently not supported by Node.js native modules, including:SOCK_SEQPACKET) socketsSOCK_DGRAM) socketsSO_REUSEPORTenabled TCP net.Servernode-unix-socketis a napi-rs based Node.js addons and:We use
SOCK_SEQPACKETsockets for in our internal APM.Tested Platforms & Node.js
Installation
API Documents
API Documents
Seqpacket Sockets
SOCK_SEQPACKETsockets are likeSOCK_STREAMsockets while they keep message boundaries.Note that
SOCK_SEQPACKETsockets don’t work on MacOS.Example
Online Example
Dgram Sockets
Example
Online Example
SO_REUSEPORTenabled TCP net.ServerThe cluster module share server ports by accepting new connections in the primary process and distributing them to worker processes.
With
SO_REUSEPORT, sockets will be distributed by kernel instead, and which should be more performant especially for scenario of having a lot of short-lived connections.For example, the arrow in the image below shows cpu usage of a PM2 primary process which we found in our environment.
Note that
SO_REUSEPORTmight behave much differently across operating systems. See this post for more information.Example
Online Http Server Example
CONTRIBUTING
CONTRIBUTING.md
Development
npm run build && npm run testLICENSE
MIT