【问题标题】:Need inputs for Database Tuning using Spring and Dbcp Connection pool需要使用 Spring 和 Dbcp 连接池进行数据库调优的输入
【发布时间】:2014-10-07 07:16:07
【问题描述】:

我在我的项目中使用 Spring 并实例化 dataSource,如下所示。

@Bean(destroyMethod="close")
    public DataSource restDataSource() {

        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(env.getProperty("hibernate.connection.driver_class"));
        dataSource.setUrl(env.getProperty("hibernate.connection.url"));
        dataSource.setUsername(env.getProperty("hibernate.connection.username"));
        dataSource.setPassword(env.getProperty("hibernate.connection.password"));
        dataSource.setInitialSize(env.getRequiredProperty("hibernate.dbcp.initialSize", Integer.class));
        dataSource.setMaxActive(env.getRequiredProperty("hibernate.dbcp.maxActive", Integer.class));
        dataSource.setMaxIdle(env.getRequiredProperty("hibernate.dbcp.maxIdle", Integer.class));
        dataSource.setMinIdle(env.getRequiredProperty("hibernate.dbcp.minIdle", Integer.class));
        return dataSource;
    }

下面是我的属性文件。

hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.username=<>
hibernate.connection.password=<>
hibernate.connection.url=jdbc:oracle:thin:@<Host>:1521:<SID>
hibernate.show_sql=true

hibernate.cache.use_query_cache=true
cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_second_level_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
net.sf.ehcache.configurationResourceName=ehcache.xml
**hibernate.dbcp.initialSize=10
hibernate.dbcp.maxActive=100
hibernate.dbcp.maxIdle=30
hibernate.dbcp.minIdle=10**

请建议:-

  1. 以粗体标记的属性的任何更改(initialSize,maxActive,maxidle,minIdle)。我的应用程序将被大约 100 个用户同时使用,总用户数约为 3000。
  2. 我正在使用 Tomcat 服务器来部署我的应用程序。我应该使用 JNDI 进行连接而不是直接指定连接属性吗?上述使用连接的方式是否适合生产系统?

【问题讨论】:

  • 我建议使用 HikariCP 而不是 commons。还有this 很好地解释了池大小以及为什么大池大小不起作用/扩展,甚至会减慢您的应用程序。

标签: spring connection-pooling apache-commons-dbcp


【解决方案1】:

我建议使用 HikariCP 而不是 Commons DBCP(我最近在这方面有很好的经验,或者如果您已经在使用 tomcat,请改用 Tomcat JDBC

有很多关于池化的文章(请参阅here 以获得很好的解释,here 以获得 Oracle 的简短视频)。简而言之,大型池不起作用,并且可能会使性能变差。

经验法则/公式(也在文章中提到)是使用

连接数 = ((core_count * 2) + Effective_spindle_count)

其中core_count 是您服务器中的(实际)内核数,effective_spindle_count 是您拥有的磁盘数。如果你的服务器有一个大磁盘和 4 个核心,它会导致一个大小为 9 的连接池。这应该能够处理你需要的东西,添加更多只会增加监控、线程切换等的开销。

【讨论】:

猜你喜欢
  • 2013-01-06
  • 1970-01-01
  • 2019-03-03
  • 2011-02-08
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多