1

I have a NodeJs project on app engine (GAE) .

Whenever there is an unexpected crash in a service call the NodeJs has to restart (I believe this is normal) , however, this leaves the whole server unaivailable for a couple of seconds which may affect other users.

I was thinking on creating two instances of the server so that if one instance fails, the other can still attend the requests.

However, I’m not certain this will bring more work, as the node js project does some initialization procedures and has some cron tasks scheduled. If I create more instances will chron tasks be duplicated?

Or which is the best way to manage redundancy on this kind of environment?

htafoya
  • 18,261
  • 11
  • 80
  • 104

1 Answers1

1

To always have 2 instances running, you do this in app.yaml set

automatic_scaling:
  min_instances: 2

https://cloud.google.com/appengine/docs/standard/python/config/appref#scaling_elements

Chron tasks will not be duplicated.

This is the way to have this type of redundancy, but it comes at the cost of having to always pay for 2 instances

But, what's going on when you actually get an "unexpected crash in a service call". That doesn't sound normal.

Alex
  • 5,141
  • 12
  • 26
  • May not be "normal", but simply a parameter that wasn't processed correctly, a scenario that was not contemplated, or even a typo that somehow went through QA. Similar to when you open a PHP page and you get an error all over the place, but instead of simply being that page, it restarts the whole node server. – htafoya Mar 07 '19 at 23:01
  • In general errors should be isolated the process handling the request (i.e. a server returning a 500 doesn't mean the whole server crashed). The only kinds of errors that crash / restart the server are things like memory leaks. Furthermore, in those situations I have had a whole app engine project get stuck in an infinite crash loop which effected all instances. But these should be exceedingly rare. Maybe you have a stack trace that illustrates what you're seeing – Alex Mar 07 '19 at 23:37
  • maybe my terminology is incorrect, the PHISYCAL SERVER doesnt crash, what is restarted is the node app (server) running on it. But while it is being restarted it cannot receive any request. If you have used nodejs you may know that any exception will turn down the project and you have to use "npm start" again to restart it. GAE does this automatically. – htafoya Mar 08 '19 at 01:00
  • Huh, that sounds brutal. GCP's load balancers are going to divide the inbound requests amongst your instances. So if npm is restarting, but the instance is still "up" in the eyes of GCP, traffic will still get routed to it, so adding instances will help but won't fix your problem. Is there no way to do something like have all your request handlers inherit from a `base_handler` and in that `base_handler` you have a try-catch that will be able to capture exceptions? There are some interesting suggesstions here https://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling – Alex Mar 08 '19 at 01:34