jkyberneees / low-http-server

HTTP Server implementation in top of uWebSocket.js
MIT License
50 stars 7 forks source link

Clustering attempt will show warning on non-Linux platforms. #4

Closed schamberg97 closed 4 years ago

schamberg97 commented 4 years ago

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.

schamberg97 commented 4 years ago

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