uWebSockets.js clustering doesn't really work on any platform other than Linux, since it depends on Linux kernel features. This can be proven with this code:
const cero = require('../src/server')
const { Worker, isMainThread, threadId } = require('worker_threads')
const numCPUs = require('os').cpus().length
if (isMainThread) {
console.log(`Master ${process.pid} is running`)
for (let i = 0; i < numCPUs; i++) {
new Worker(__filename)
}
} else {
const server = cero({})
server.on('request', (req, res) => {
res.end(threadId.toString()) // willl always send '1' on non-Linux platforms.
})
server.listen(3000, () => {
console.log(`Server(${threadId}) listening on http://0.0.0.0:3000`)
})
}
As such, we need to show warning to the users, so they are aware of the issue and why there is no performance gain.
Additionally, it would make sense to point out in the docs that the best approach is to create uWebSockets.js servers on different ports that are then load balanced by something else
uWebSockets.js clustering doesn't really work on any platform other than
Linux
, since it depends onLinux
kernel features. This can be proven with this code:As such, we need to show warning to the users, so they are aware of the issue and why there is no performance gain.