sitegui / nodejs-websocket

A node.js module for websocket server and client
MIT License
736 stars 155 forks source link

Multithreading. How to? Cluster? #25

Closed q3wzeck closed 8 years ago

q3wzeck commented 8 years ago

Have a large project with this ws server, so now at peak cpu core with process have ~60-70% load. How to add miltithreading support to this server? Please with example. Structure is: Main ws server who accepts all clients connections and this server starts child processes on remote VPS. This remote processes are linked with clients via main ws. ><

sitegui commented 8 years ago

Hi,

You can do this by hand with node's cluster API or using some external tool for that.

I use PM2, because it just works (assuming your logic is ready for multiple processes). All you have to do is (go to their docs for details):

$ npm install -g pm2 $ pm2 start app.js -i 0

But either way, nodejs-websocket implements the websocket client/server logic only. Load-balancing, multiple machines/processes are not what this module is about.

Good luck on your multi-core adventure ;) Closing this, but feel free to share your approach