How to scale socket.io during recovery?

I am trying to scale socket.io working on recovery. I was able to configure it to work perfectly on a single instance of nodejs. Now, when I scale my application to four instances, the ecosystem of the application is broken (i.e. Events were not synchronized correctly between clients).

I am looking for examples of how to set up sticky sessions using restify. Or how is it done now?

An update on a sticky session was a year ago: Socket 1.0 Update / Scalability .

I found these two blogs in customization, but both of them used Express and were also written over a year ago:

As I make a mute API, I think Express should not be used. Is this the recommended way of thinking or should I just use Express?

package.json:

  "dependencies": {
    "hiredis": "^0.4.1",
    "pouchdb": "^4.0.3",
    "pouchdb-upsert": "^1.1.3",
    "redis": "^2.0.1",
    "restify": "^4.0.0",
    "socket.io": "^1.3.7"
  }

Any help would be appreciated!

+4
source share
1 answer

Socket.io will only support your server data ↔ synchronized in one instance, due to the fact that Node is single-threaded and lives on the same CPU core. To synchronize multiple instances, you will need a higher level message management method. Socket.io recommends an instance of Redis. Also this is a repo: http://socketcluster.io that handles the same problems for you.

+1
source

Source: https://habr.com/ru/post/1610500/


All Articles