I'm using MongoDB as an analytics platform (not a primary datastore) from classic GAE/Java. I had to hack the driver pretty seriously with some help from the author. I haven't looked at the Python driver code, but in very general terms, what I had to do:
* Stop the monitoring thread from being created * Manually pump the monitor method once on startup * Pump the monitor method whenever an error occurs * Wrap all mongo access in a proxy that retries everything once (sockets timeout frequently) This is not for the faint of heart but it is working very well for me. I suspect it might be more complicated if using a cluster (I have only a single instance). I wouldn't use this to treat mongo as a primary datastore, but for running aggregations on a slave copy it's great. And at $150/mo for a 26G compute engine instance it's an order of magnitude cheaper than Cloud SQL and way faster than BigQuery or Keen (at least, for my dataset). Here's my forked Java driver: https://github.com/GearLaunch/mongo-java-driver Looking at the diffs might help you attack the Python driver, dunno. Suerte, Jeff On Tue, Nov 3, 2015 at 11:39 PM, Minie Takalova <[email protected]> wrote: > Hello > > I'am trying to build application on GAE which use MongoDB hosted at > Mongolab provider. > Connection work, if I made new connection every request, but if I want to > reuse once established connection, GAE freeze and die on timeout. > I believe that exist some simple way, how to do that such simple task. > > > ----- This is woring, but open new connection every request: ------ > def get_database_connection(): > client = pymongo.MongoClient(MONGO_URI) > DBCONN = client.get_default_database() > return DBCONN > > DBCON = get_database_connection() > ... do something usefull with DBCONN ... > ... not store connection anywhere .... > ... end request .... > > > ---- This freeze GAE and die on timeout --- > def get_database_connection(): > if "DBCONN" in globals(): # look for open connection in > instance memory > return globals()["DBCONN"] > client = pymongo.MongoClient(MONGO_URI) > DBCONN = client.get_default_database() > globals()["DBCONN"] = DBCONN # store connection to instance memory > return DBCONN > > DBCONN = get_database_connection() > ... do something usefull with DBCONN ... > ... end request .... > > -------- > > Probably GAE module with backend thread can be uset to keep connection > open in separate thread, but after many hours I can“t find working solution. > Hope somebody can experience with this usecase and can help me. Also link > to well-tried solution will be helpfull. > > Have a nice day. > > > > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-appengine. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-appengine/33df8ac3-d561-4726-8fbe-89bcaf14a9e0%40googlegroups.com > <https://groups.google.com/d/msgid/google-appengine/33df8ac3-d561-4726-8fbe-89bcaf14a9e0%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-appengine. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/CADK-0uj%3DNxfJCjZYMM6ORsv4DJOqKJVWb2gHR29T5H-Bsw6hPw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
