Comment on page
Before installing the CLI version, make sure you have the required dependencies to build soketi:
- Python 3.x
gcccompiler and the dependencies for build
The following example works for Ubuntu. For other distributions, consider using the equivalents.
apt install -y git python3 gcc build-essential
Node.js LTS (14.x, 16.x, so on) is required due to uWebSockets.js build limitations.
soketi may be easily installed via the NPM CLI:
npm install -g @soketi/soketi
After installation, a soketi server using the default configuration may be started using the
By default, this will start a server at
127.0.0.1:6001with the following application credentials:
- App ID:
- App Key:
The credentials are used to authenticate your frontend and backend applications in order to be able to send messages and receive them in real time.
To keep the soketi server alive permanently, you should consider installing a process manager such as supervisor, a daemon that can run and restart processes in the background. After installing Supervisor, you may use the following example configuration as a good starting point for launching a soketi server:
As you can see in the configuration above, a single soketi server will be started, and this server will auto-restart on failure. Logs will be written to
It's important to note that the
stopsignalconfiguration options should be set as in the example above. If necessary, you can increase
stopwaitsecsto a larger value. This is the number of seconds Supervisor will allow soketi to gracefully close all connections when the server is stopping or restarting.
In Linux environments, everything is a file, including active sockets. To track socket connections, soketi is creating file descriptor for each connection. In some cases, you may run into a soft limit on file descriptors set by your operating system. In this situation, you can set the Supervisor
minfdsconfiguration option to a higher value to allow the operating system to handle more connections.
Node.js is meant to be ran on one CPU at a given time. This means that multi-threading isn't actually multi-threading in its common sense. To fix this problem, you may use the PM2-ready binary that is shipped with any soketi installation:
pm2 start soketi-pm2 -- start
The only remaining caveat is that the processes are like they are horizontally scaled. You may want to configure horizontal scaling with the cluster adapter, unless you are also scaling across multiple different instances, in which Redis is the recommended adapter.