-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Google App Engine and External Database #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@benguild this may interest you since you use GAE and everyone knows Google Cloud SQL is prohibitively expensive. |
@pjebs Are you connecting to an external SQL server, or using this with Google Cloud SQL? I use smaller Google Cloud SQL instances and have a "memcache" layer in between to reduce the load. |
I just started using an external SQL server instead of Cloud SQL. Of course caching is important, but there are plenty of cheaper managed databases around or you can manage your own. I believe even AWS RDS is slightly cheaper that Cloud SQL. |
Are you sure you can't use this context? https://github.com/benguild/GAEBridge/tree/master/context |
If you are trying to connect to something outside the Google App Engine ecosystem, you need to use URLFetch or SocketAPI. Both require the current request to create a google context. There is no other way to connect to anything externally. The context will automatically expire after the request cycle is over. I believe (???) this will invalidate the database connection made during the request, after the request is over. Your library is only useful during any specific request. |
So this context is separate from the request's context? |
And the socket connection only exists in that context, which expires? |
Can you pass the context between request contexts? |
A1: The context is the request's context. You can use your library to pass the context to the dial function if you want. A3: You definitely can't pass contexts between individual requests (hence why I put the A2: Not sure what happens to the connection after request cycle expires. If it does invalidate, I'm asking the authorities if this is a good reason to close connection and depart from their directive. |
Gotcha. Well it definitely sounds like a limitation of GAE if you're losing access to an actual connection between requests. You definitely cannot "pool" them in this case. I think you should use Google Cloud SQL (which avoids this problem due to internal networking), or just close the connection pool between requests on your external box. Or, consider other hosting... because the added latency of an external DB server doesn't seem worth it if you're also losing the pool. You may have outgrown the practicality of GAE based on your budget. |
For the record, I use the GAE "memcache" service heavily for this reason. |
In a super busy GAE application, you probably need to use memcache, read replicas and master Cloud SQL |
Honestly, "memcache" is fine as a "read replica" in most instances IMO, as long as your application is designed to utilize it. The only time data is read from the DB is if the cache is lost or entries are purged without just being updated. What's your exact issue at this time? |
No issue. I just moved over to an external database so was wondering what to do regarding disabling connection pooling. I read some documentation regarding this driver (which I can't find anymore) that suggested that if you call |
@arnehormann @julienschmidt I have done some research and diagnosed the problem and found out some possible solutions. There will need to be a slight change at the driver level. The change was done for the postgres driver: https://github.com/lib/pq/pull/287/files 1 ) GAE's socket API (
https://cloud.google.com/appengine/docs/quotas?hl=en#Sockets |
Where is the limitation written in doc? |
@methane That context must be passed to the
|
Where is the limitation written in the doc??
The functions receives
Where is the limitation written in the doc??? |
https://cloud.google.com/appengine/docs/go/reference#NewContext Good Question regarding where is the limitation listed. GAE operates in a sandboxed environment. In order to escape, there are only 2 ways: https://cloud.google.com/appengine/docs/go/sockets/reference#Conn.SetContext (It might be possible to infer it from reading If you don't attach a context to socket api via: you get this error: |
@pjebs Just to nudge this since I don't have your email (you can grab mine off my website if you want!) ... Have you been satisfied with Google Cloud SQL 2nd generation? It seems like their use of |
I've heard there are issues with using this driver with Gen2 CloudSql. I'm still not in production so just using a simple Gen 1 for now. |
@pjebs Issues like what? I haven't had any problems and we're in production. Send me an email so that we're not hogging the thread :) |
The issues with this driver: #484 |
I posted a follow-up to #484. No issues in production besides Google's documentation being wrong. Maybe it's been updated now, but like I said we're using it in production without problems. |
I attempted to work around If anyone wants to help go ahead. |
This is not an issue for new GAE/Go based on gVisor. |
I solved how to connect to an external database using Google App Engine (Standard Environment): See #457
The new issue is:
In order to connect externally, I need to use socket API which requires a
request
to create the Google Context.This leads me to believe that we can't allow this driver to use connection pooling due to a new request requiring a new context. Am I correct in this assumption?
If we can't use connection pooling, what's the best way to manage it?
Is there a setting to disable connection pooling (i.e. max connection 1, 0 second idle time etc) OR create a connection at start of request cycle and close it and end of request cycle.
The documentation says DO NOT CLOSE connection. Is this a good exception to the directive?
The text was updated successfully, but these errors were encountered: