如何选择最大连接池大小? [英] how to choose maximum connection pool size?

查看:185
本文介绍了如何选择最大连接池大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < property name =hibernateProperties> 
<道具>
< prop key =hibernate.c3p0.max_size>?< / prop>
< /道具>
< / property>

它只是一个随机数猜测?或者是否有任何研究表明针对特定用例使用特定范围?

解决方案

好吧,假设你正在谈论一个生产系统,那么随机数猜测绝对不是答案。实际上,随机数猜测从来不是生产环境中任何配置的答案。连接池属性(如 max_size )取决于一个几个因素:


  • 预期使用。例如,如果您期待10个并发用户的典型使用模式,偶尔会有20个用户突然出现,那么即使您认为您的机器可以处理该数字,也没有必要将数字50设置为最大大小。尽管看起来似乎毫无害处,但您必须记住,数据库连接是一项昂贵的资源,有时您可能希望实际上限制使用以符合您的期望,只要将自己的假设进行测试并了解真正的,类似于生产的,系统的使用模式,并防止您的应用程序成为资源管理器,从而可能影响其他应用程序。

  • 可用资源。如果您知道(并且很容易验证)您的数据库一次只能接受30个连接,那么设置大于30的数字是无意义的,无论应用程序的使用模式如何。 $ b
  • 应用程序设计。您的应用程序将主要使用短期连接吗?长期连接?你是否设置了JDBC调用的超时,所以你的JDBC调用是有时间限制的?例如,当您知道每个操作的超时设置为30秒时,配置连接池的方式就会有所不同,相比之下,您知道如何设置一个连接池超时时间为2分钟。

  • 特定的产品考虑因素。我不确定 c3p0 ,但是某些提供连接池机制的容器将自己的因素带入方程中。如果您正在使用容器提供的连接池功能,则应该阅读该容器的文档以查看容器的供应商是否对配置它们提供的连接池机制有所了解。

  • b


    ...只是不要猜测一个数字。



    ...而且,吨只是假设产品的默认值。


    <property name="hibernateProperties">
      <props>           
        <prop key="hibernate.c3p0.max_size">?</prop>
      </props>
    </property>
    

    is it just a random number guess ? or are there any studies that suggest to use a particular range for a specific use case?

    解决方案

    Well, assuming that you are talking about a production system, then "random number guess" is definitely not the answer. Actually, "random number guess" is never the answer for any sort of configuration in a production environment. Same goes for "just accepting the product's defaults".

    Connection pool properties (such as max_size) depend on a few factors:

    • Anticipated use. For example, if you are expecting a typical usage pattern of 10 concurrent users, with an occasional burst of 20 users, there is little point in setting the number 50 as a maximum size even if you think that your machine can handle it. While it seems harmless at first sight, you have to remember that database connections are an expensive resource and, sometimes, you might want to actually cap the usage to match your expectation, if only to put your own assumptions into test and getting to know the real, production-like, usage pattern of the system and to prevent your application from being a resource hog, potentially affecting other applications.

    • Available resources. If you know (and that is easy to verify) that your database can only accept 30 connections at a time, then setting a number larger than 30 is senseless, regardless of the application's usage pattern.

    • Application design. Is your application going to mainly use short-lived connections? long-lived connections? Are you setting up a timeout for JDBC calls, so your JDBC calls are time-limited to begin with? For example, there's a difference in how you would configure a connection pool when you know that you're setting a timeout of 30 seconds per operation, comparing to how you would define that pool knowing that you set a timeout of 2 minutes.

    • Specific product considerations. I am not sure about c3p0, but certain containers that provide connection pooling mechanisms carry their own factors into the equation. If you are using the connection pooling functionality provided by a container, you should read that container's documentation to see whether the container's vendor has some insight with regards to configuring the connection pooling mechanism they provide you with.

    ... Just don't guesstimate a number.

    ... And don't just assume product's defaults.

    这篇关于如何选择最大连接池大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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