2

Is there any way to send requests to all active instances of a module/service in Google App Engine?

If I can get the list of all the active instances ids, I could make a request like https://instance-dot-version-dot-service-dot-app-id.appspot.com for each instance.

I need this to change some memory's global variables (that saves me requests to datastore or memcache and time) in very unusual cases. If they were frequent changes I obviously would prefer to use memcache...

Rene Marty
  • 531
  • 4
  • 14
  • While Dan has posted an answer, I am not sure that's really the best approach for what you need to achieve. Do you think you can elaborate further? – BrettJ Dec 01 '16 at 06:51
  • You can have a flag in RAM memory of the instance, in MEMCACHE or DATASTORE (or other NSQL). The time to get the value of that flag could be 0.001, 2 or 50 ms (example) depending the selected storage. If all the requests of my app read that flag, you can save money and time if you read it from RAM memory of the instance (suppouse 10 M request/day and do the numbers). When the instance start, you read the value from Datastore and put it in RAM as global variable. But if the flag changes, I'm looking for a way to send a message to ALL INSTANCES to update the value of the Flag in their RAM. – Rene Marty Jul 26 '17 at 15:34
  • In my previos example, that flag could change only once a Month or in case some Google Services fails (like GAE taskqueues), but in the moment that happens we need an inmediate propagation. The current solution is to flush memcache and upload again the last version of the app, so all the instances are initialized and restarted with the new flag value... I'm looking for a more elegant way to do this. I need it for AUTOMATIC SCALING INSTANCES. – Rene Marty Jul 26 '17 at 15:38

1 Answers1

1

You can get the list of instances for a specific service version using the Google App Engine Admin API's REST apps.services.versions.instances.list method:

Lists the instances of a version.

HTTP request

GET https://appengine.googleapis.com/v1/{parent=apps/*/services/*/versions/*}/instances

The URL uses Google API HTTP annotation syntax.

See also the corresponding Google App Engine Admin API Client Library for Python's pydoc page here.

With the list of instances you can, as you mentioned, use GAE's routing via URL to send requests to each particular instance as desired.

Important note related to this assumption in the question:

If I can get the list of all the active instances ids, I could make a request like https://instance-dot-version-dot-service-dot-app-id.appspot.com for each instance.

from Targeted routing:

Note: Targeting an instance is not supported in services that are configured for auto scaling or basic scaling.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • 1
    This solution doesn´t work for automatic scaling instances. I get de instances ID's but the instance.service.version.app.appspot.com request does not work. The documentation states "Targeting an instance is not supported in services that are configured for auto scaling or basic scaling." – Rene Marty Jul 26 '17 at 15:27
  • That's true, indeed, but I'd argue that's an issue of the context set by the original post which states `I could make a request like https://instance-dot-version-dot-service-dot-app-id.appspot.com for each instance.` :) – Dan Cornilescu Jul 26 '17 at 15:46
  • I tried all the notations variations but does not work. My instances are automatic scaling, doesn't work for that said the documentation. I expect they could change this in the future. – Rene Marty Jul 26 '17 at 15:57
  • ever find a solution for automatic scaling? – Patrick Jackson Oct 10 '17 at 21:14
  • Not as far as I know (but I didn't check lately). – Dan Cornilescu Oct 10 '17 at 21:16