Hey Prasanga, 

I'm unsure what you meant by your last post. Do you think you could clarify 
in more precise language what behaviour you're referring to? Do you mean 
the fact that "Sockets may be reclaimed after 2 minutes of inactivity; any 
socket operation keeps the socket alive for a further 2 minutes.", as 
mentioned in the docs 
<https://cloud.google.com/appengine/docs/python/sockets/#limitations_and_restrictions>
?

Reviewing this thread, I'd say that forcing a software implementation 
dependent on opening OS threads into the App Engine mold simply may not be 
the best use of dev cycles. It might be best to delegate the mongoDB 
connection functionality to a GCE instance which holds connection pools on 
proper OS threads. For modest loads, one such instance ought not to be much 
of a bottleneck because of the low-latency nature of simply forwarding 
requests and data. It would act basically like a proxy.

The other option is to connect to Mongo via REST, although this is more 
expensive, as it uses higher layers of the protocol stack, with HTTP 
headers, etc.

Anyways, let us know your thoughts Prasanga!

Cheers,

Nick
Cloud Platform Community Support 

On Wednesday, June 29, 2016 at 12:43:11 AM UTC-4, Prasanga Siripala wrote:
>
> I believe to keep the connection alive, SOCKET API requires a new request. 
> Therefore after the request is finished, you can't reuse connection.
>
> On Wednesday, November 4, 2015 at 6:39:17 PM UTC+11, Minie Takalova 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 https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/7cca5ff6-e37b-47ef-b70d-e11d78580532%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to