node.jsgoogle-app-enginesocket.iogcloud-nodegoogle-managed-vm

gcloud socketIO is not working on multi-instances


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.


Solution

  • 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:

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

    Best of luck!