Friday, June 22, 2018

how to use socket.io through google load balancing

Leave a Comment

We are having some problems when trying to connect socket.io to a node.js compute engine instance through google load balancing.

If I connect from my browser directly to the external IP of my node.js everything works fine.

If I try to connect to this same node.js through the load balancing (which will be the production architecture), the socket keeps disconnecting all the time.

We tried to configure Load Balancing with sessionAffinity without success.

Any tips? Thanks

1 Answers

Answers 1

By Default The timeout set for http load balancing is 30 seconds by default (Source), this applies to web sockets which in turn is used by socket.io when the protocol is supported by the back-end. Therefore you need to do the following to increase the time out (Source).

To configure the timeout setting:

  • GO TO THE LOAD BALANCING PAGE
  • Select the Edit pencil for your load balancer.
  • Select Backend configuration.
  • Select the Edit pencil for the Backend service.
  • On the line for Protocol, Port, and Timeout settings, select the Edit pencil.
  • Enter a new Timeout Setting in seconds.
  • Click the Update button for the load balancer.
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment