带有Google App Engine和Google Cloud SQL的连接池 [英] Connection pool with Google App Engine and Google Cloud SQL

查看:122
本文介绍了带有Google App Engine和Google Cloud SQL的连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于将数据库连接池与Google App Engine一起使用存在很多问题,但是最近发生了很多变化.到目前为止,我永远无法获得连接池来使用GAE.但是,我认为最近的一些发展可能允许连接池起作用,这可能就是为什么它在Google文档中有所提及(该文档似乎最近已更新).

There are numerous questions about using a db connection pool with Google App Engine, but a lot has changed recently. Up to this point, I could never get a connection pool to work with GAE. However, I think some recent develops may allow connection pooling to work, which may be why it is mentioned in the Google documentation (which seems to have recently been updated).

https://cloud.google.com/sql/docs/mysql/connect-app-engine

有人可以确认可以使用连接池吗?

Can someone confirm that connection pools can be used?

1)我们使用了Google Cloud SQL 1st gen,该数据库可能会停用(进入睡眠状态).这会使所有现有连接失效.

1) We used Google Cloud SQL 1st gen and the database could deactivate (go to sleep). This would make any existing connections stale.

使用第二代数据库时,不会停用数据库.因此,这可能可以解决问题.

With a 2nd gen database, there is no deactivtion of databases. So this may address the problem.

2)许多连接池实现都使用线程.

2) Many connection pool implementations used threads.

GAE支持Java 8,看起来允许使用线程.

With Java 8 being supported on GAE, it looks like threads are permitted.

3)有人建议GAE数量有限的数据库连接(12)是使用连接池的原因.可以将连接池大小设置为GAE的限制,因此应用程序永远不会超过该限制.

3) Some people suggest that GAE's limited number of database connections (12) are a reason to use connection pools. The connection pool size could be set to GAE's limit and thus an app would never exceed the limit.

a)首先,基于数据库的大小,文档表明连接的数量要多得多.

a) First, documentation indicates a much larger number of connections, based on the size of the database.

https://cloud.google.com/sql/docs/quotas

b)其次,如果GAE应用程序有限制,是每个服务器实例还是整个GAE应用程序都有限制?

b) Second, if there is a limit for a GAE app, is the limit per individual server instance or for an entire GAE app?

任何确认上述想法有意义的确认都会得到赞赏.

Any confirmation that the above thinking makes sense would be appreciated.

推荐答案

关于1)是的,第二代的Cloud SQL实例,除非用于维护等,否则您的实例不会停用.

Regarding 1) Yes, the Cloud SQL instances of 2nd generation, your instances don't deactivate unless it's for maintenance etc.

2)我不明白为什么您不能使用线程连接到第二代Cloud SQL数据库.使用Java 8,您绝对可以做到这一点.要检查您打开了多少个线程,可以运行mysql> SHOW STATUS WHERE Variable_name = 'Threads_connected';

2) I don't see why you can't use threads to connect to a 2nd generation Cloud SQL database. With Java 8, you can absolutely do that. To check how many threads you have open, you can run mysql> SHOW STATUS WHERE Variable_name = 'Threads_connected';

对于3a),我将使用您已经提供的官方文档链接,但是请记住,数据库连接会消耗服务器和正在连接的应用程序上的资源.始终使用良好的连接管理做法,以最大程度地减少应用程序的占用空间,并降低超过Cloud SQL连接限制的可能性.过去确实有12个连接的限制,但是现在不存在了.

For 3a), I would go with the official documentation link that you provided already but remember that database connections consume resources on the server and the connecting application. Always use good connection management practices to minimize your application's footprint and reduce the likelihood of exceeding Cloud SQL connection limits. The limit of 12 connections was indeed in place in the past but it doesn't exist anymore.

3b)当限制或配额指的是Google App Engine应用程序时,则适用于整个应用程序,除非指定为每个实例.更具体地说,对于Cloud SQL连接,您可以在此处找到限制,实际上有一个特定于实例的限制.在标准环境中运行的每个App Engine实例,您的并发连接不能超过100个.

3b) When a limit or quota refers to a Google App Engine app, then it's for the whole app unless it's specified that it's per instance. More specifically for Cloud SQL connections, you can find the limits here and there is actually a limit that is specific to instances. You can't have more than 100 concurrent connections for each App Engine instance running in a standard environment.

希望对您有帮助!

这篇关于带有Google App Engine和Google Cloud SQL的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆