高的 Hibernate 连接池大小

huangapple go评论66阅读模式
英文:

High Hibernate Connection Pool Size

问题

我目前在运行一个游戏,其中使用Hibernate作为我的对象关系映射(ORM)工具。最近,有许多玩家同时登录游戏。这导致了一个Hibernate的异常:

Exception in thread "main" org.hibernate.HibernateException: 内部连接池已达到最大大小,当前没有可用连接!

我将连接池属性设置为10。我首先考虑的是将连接池大小增加到100,甚至1000,但我不确定这样做会有什么影响。我猜测,当有100多个线程同时运行到数据库时,高连接池大小可能会拖累系统。

在高连接池大小的情况下,主要受影响的是性能吗?设置连接池大小时还有其他需要考虑的因素吗?

英文:

I currently run a game in which I use Hibernate as my ORM. Recently, we had many players log into the game all at the same time. This threw a Hibernate

Exception in thread "main" org.hibernate.HibernateException: The internal connection pool has reached its maximum size and no connection is currently available!

I have my pool properties set to 10. My immediate thought is to simply increase the pool size to 100, or even 1000, but I'm not sure what the impacts of this are. My guess is a high pool size could bog down a system when there are 100+ threads running concurrently to the database.

Would performance be the primary aspect impacted by high pool sizes? Is there anything else I should consider when setting a pool size?

答案1

得分: 1

最大可使用的连接数等于您的应用程序用于处理请求的线程的最大数量。实际数量会较少,这取决于您的线程除了连接数据库之外的工作类型。

您应该测试您的数据库能够处理那么多的连接数。

连接占用相当多的内存,因此您应该确保您的Java服务器也具有足够的内存来处理它们。

此外,您的连接池应该具有某种可以设置的“等待超时”,在抛出异常之前可以设置这个超时。这样,一个线程就可以等待释放连接。

英文:

The maximum number of connections you could use is equal to the maximum number of threads your app has for handling requests. The real number would be less based on the kind of work that your thread does besides connecting to the database.

You should test that your database can deal with that number of connections.

Connections take a fair amount of memory, so you should look that your Java server has enough memory to handle them too.

Also your connection pool should have some kind of "wait timeout" you can set, before launching that exception. So a thread can wait for a connection to be released.

huangapple
  • 本文由 发表于 2020年10月4日 06:07:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64189451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定