Scaling with sticky sessions and websockets

后端 未结 1 663
走了就别回头了
走了就别回头了 2021-02-04 14:20

Initially we have two AWS EC2 instances with node.js running behind a load balancer with sticky sessions. As the load increases more instances are added.

But we are faci

相关标签:
1条回答
  • 2021-02-04 14:38

    The solution was an Application Load Balancer (see comment).

    1. At first we had to disable polling, because this did not work with the rest. This is done by defining the transports manually.

      let ioSocket = io('', {
          path: '/socket.io-client'
          transports: ['websocket']
      
    2. After that we set up a standard application load balancer with two target groups: one for websockets and one for all other requests. The rule for the websocket target group matches a specific path via regex:

    1. Last problem was scaling: if one of the instances shuts down because of lower load on the cluster connections may get lost. This was fixed with a simple reconnect after a disconnect in the client (in our case an angular application):

      [...]
      this.socket.on('disconnect', () => {
          // Reconnect after connection loss
          this.connect();
      });
      [...]
      
    0 讨论(0)
提交回复
热议问题