gcloud socketIO is not working on multi-instances

651 views Asked by At

I am working with socketIO + Nodejs over gcloud app-engine with managed vms. I am facing a problem that when I use manual scaling, the gcloud working well with sockets.

But when I use dynamic scaling, sockets not working at all, I think it doesn't work because of the port forwarding problem with two instances! here's my app.yaml instances handling that works.

 manual_scaling:
  instances: 1

 resources:
  cpu: 0.1
  memory_gb: 0.1
  disk_size_gb: 10

When I remove them, sockets not works at all. Is there's any recommendation or a work around. As I am going to serve a very large number of socket requests (2 million/day). If no work around found. What is the specs that I should use for one instance to handle all of these requests, or how can I calculate them?

Thanks.

1

There are 1 answers

1
Justin Beckwith On BEST ANSWER

Google Cloud does not natively support load balanced web sockets. There are a few options you can use to work around the problem.

One option is to route websocket traffic directly to the VM instance, instead of through the cloud load balancer. You can see an example of doing that here:

https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/websockets

This will work, but you should know about the downsides:

  • It doesn't natively work over HTTPS
  • Once a week VM instances in Managed VMs are recycled, leading to dropped connections.

Another option is to use a 3rd party service like pubnub or pusher:

Best of luck!