And is there a way to send a request directly to that server?
5 Answers
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()
-
In Java I'm trying String
instanceId = System.getProperty( "INSTANCE_ID" );
but it returns null. Anyone know what I'm doing wrong?– TomJan 25, 2013 at 0:33 -
1@Tom: Hi Tom, in Java the instance ID is stored at AppEngine's environment attributes map. See my answer in stackoverflow.com/a/15111345/752918 for a code example. Feb 27, 2013 at 13:01
-
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.
-
I wanted to see if it's possible to implement a long polling service. Chat like service. I need to know what instance the client is connected to so I can notify that instance.– TrungJul 31, 2012 at 5:18
-
see developers.google.com/appengine/docs/java/channel . In general, using Channel API is a better choice than polling in situations where updates can't be predicted or scripted, such as when relaying information between human users or from events not generated systematically. Jul 31, 2012 at 5:21
-
thanks. seems like a good solution. but it costs $1/10,000 channel opened. Need to do some math to see if this is a viable option.– TrungJul 31, 2012 at 5:48
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.
-
It doesn't mean that there's no legitimate usage of this feature. This can be useful if I want to send a specific command for a particular instance, such as clearing my in-memory cache. I have opened a feature request for this in here. Aug 29, 2012 at 5:42
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
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