2014-10-07 55 views
1

我在我的項目中使用Spring並實例化dataSource,如下所示。需要使用Spring和Dbcp連接池進行數據庫優化的輸入

@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進行連接,而不是直接指定連接屬性?上面的方式使用良好的生產系統連接?
+0

而不是我會建議[HikariCP](https://github.com/brettwooldridge/HikariCP)。另外還有[this](https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing),它對游泳池大小有很好的解釋,爲什麼大游泳池游泳池不能正常工作/縮放,甚至可能會減慢你的速度應用。 – 2014-10-07 08:38:42

回答

3

相反下議院DBCP的我會建議使用HikariCP(我在與非常好的經驗最近,或者如果你已經在使用Tomcat的,而不是Tomcat JDBC

有寫在poolsizing很多(見here爲從Oracle的簡短視頻)一個很好的解釋和here。總之大poolsizes不工作,將可能使性能變得更糟。

拇指/公式(還提到文章的規則)是使用

連接=((core_count * 2)+ effective_spindle_count)

core_count是在你的服務器和effective_spindle_count實際)內核,你擁有的硬盤數目。如果你有一個大磁盤和4核心的服務器,它會導致一個9號連接池。這應該能夠處理你所需要的,增加更多隻會增加監控,線程切換等開銷。

+0

可以請你幫我解決這個問題http://stackoverflow.com/questions/26231165/improve-performance-on-sending-bulk-emails-through-spring-mail/26233308#26233308 – 2014-10-07 10:36:19