3

我对连接池有点困惑。我在 MySQL 数据库之上使用 Hibernate。Hibernate 的连接池策略由 c3p0 决定。

Hibernate 的连接池大小与 MySQL 之间的关系是什么?

我运行 Hibernate 的代码可以扩展到 AWS 上的多个实例(因此 n 个实例,每个实例的 Hibernate 连接池大小为 m)。然而,所有实例都与单个 RDS MySQL 实例通信,该实例本身具有连接池大小 q。

这是否意味着如果有 n*m 个活动连接并且 n*m>q,将有连接必须在 MySQL 的队列中等待?

谢谢!

4

1 回答 1

1

Your question asks about "Hibernate's connection pool size vs MySQL's". The important distinction to keep in mind is:

  • A connection pool is an application concept, not a database one. The connection pool used by your application (i.e., Hibernate) is simply a way of speeding up the communication to the database. Since establishing each connection is relatively slow, it's more efficient to pre-establish a bunch of connections and then let your application use them as needed.

  • On the other hand, a database doesn't pool connections. Instead, it allows clients to establish connections upon request up to a max limit (e.g., the max_connections parameter in MySQL). If a client asks for a connection and the database has already hit the max limit, then a connection error will occur.

So to answer your question, if you configure your application connection pools to try to pre-establish more connections than the database will allow, you will get a "Too many connections" error from MySQL. This could be avoided by either raising the MySQL configuration parameter or by adjusting your c3p0 max pool size per instance.

于 2014-03-15T16:29:00.393 回答