How do I get an instance Id of app engine front server?

本小妞迷上赌 提交于 2020-01-01 16:56:37

问题


And is there a way to send a request directly to that server?


回答1:


Actually there is a way and it can be useful for pushing new data out to all instances of an application.

from google.appengine.api import modules
instance_id = modules.get_current_instance_id()

ref: GAE Modules Docs




回答2:


For what purpose?

If you want to test different versions, you can use traffic splitting https://developers.google.com/appengine/docs/adminconsole/trafficsplitting

That is different versions though, and not a specific instance.




回答3:


No there isn't.

Usually when someone asks something like this, they're headed in the wrong direction on app engine. Frontend servers get started and shutdown all the time. If you are designing anything that relies on a particular instance, you're doing it wrong. You need to design requests that work no matter what instance they hit.

Consider using backends if you must do that.




回答4:


I use Python and a datetime stamp to identify an instance. This instance id is set by appengine_config.py. To signal other instances I use a flag in memcache, which is checked by the __init__ of my webapp2 request handler. I use signals to other instances to flush the jinja environment and reload dynamic python code, because I could not find another way.

Here is an example of a memcache flag; signalling to reload all dynamic modules, which had been set by instance id: '2012-12-26 16:39:50.072000'

{ u'_all': { u'dyn_reloads_dt': datetime.datetime(2012, 12, 26, 16, 39, 59, 120000),
             u'setter_instance': '2012-12-26 16:39:50.072000'}} 

And I starred the feature request from : Ibrahim Arief




回答5:


With the advent of Modules, you can get the current instance id in a more elegant way:

ModulesServiceFactory.getModulesService().getCurrentInstanceId()

Also, according to this doc, you can route requests specifically to a particular instance by using a URL like

http://instance.version.module.app-id.appspot.com

Note that you need to replace the dot with -dot- to suppress the SSL certificate warning your web client may be complaining about:

http://instance-dot-version-dot-module-dot-app-id.appspot.com



来源:https://stackoverflow.com/questions/11731719/how-do-i-get-an-instance-id-of-app-engine-front-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!