How do Singletons in Google App Engine (or more generally in a distributed server environment) work?

211 views
Skip to first unread message

Shane

unread,
Jul 25, 2009, 9:45:09 PM7/25/09
to Google App Engine
Hi,

I am intrigued as to how singletons work in Google App Engine. Given
your application can be running in multiple processes (on multiple
machines) at once, and requests can get routed all off the place, what
actually happens under the hood when an app does something like:
'CacheManager.getInstance()'?

I'm just using the CacheManager as an example, but my point is, there
is a single global application instance of a singleton somewhere, so
where does it live? Is an RPC invoked? In fact, how is global
application state (like sessions) actually handled generally?

Regards,
Shane

Tim Hoffman

unread,
Jul 26, 2009, 7:08:09 AM7/26/09
to Google App Engine
Hi

It won't ever be a true singleton as each instance running would have
a copy in their memory. If the entity is predominately read only,
then it doesn't really matter
if their state is retrieved from the datastore or from memcache when
you need it. Its probably more like a borg than a singleton. The
idea of the borg pattern is you can
create as many copies you like but all share the same state.

See http://www.aleax.it/Python/5ep.html and http://code.activestate.com/recipes/66531/

The main problem will be if you start updating it/them all over the
place then you need to ensure everyone is invalidating their copy.
Which should mean you at least reload it on every request, which in
the main would guard against any real problems with shared state
getting out of date.

Rgds

Tim

vikramark singh

unread,
Jul 26, 2009, 3:40:46 AM7/26/09
to google-a...@googlegroups.com
 I guess it should be handled using virtual vm's. There are many products in market that offer Virtual VM example Terracotta. I am not sure how google is handling this, but i believe they would be using similar concepts of Virtual VMs. 
--
Vikramark
http://www.vikramark.com
Reply all
Reply to author
Forward
0 new messages