LoginSignup
4
3

More than 5 years have passed since last update.

DatasourceにDriverManagerDataSourceは使用しないほうがいいかもしれない

Posted at

DriverManagerDataSourceはテスト用?

  • 自作のapiをAWSにのせて、JMeterで負荷をかけていたのですが全然スループットが出ませんでした。ボトルネックはどこかを探していたのですが何やらDB周りが怪しいというところまでは気が付けました。
  • で、調べていくとDriverManagerDataSourceを使っていることがスループットが出ない原因ではないかという結論になりました

公式に書いてあった

NOTE: This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

Useful for test or standalone environments outside of a J2EE container, either as a DataSource bean in a corresponding ApplicationContext or in conjunction with a simple JNDI environment. Pool-assuming Connection.close() calls will simply close the Connection, so any DataSource-aware persistence code should work.

NOTE: Within special class loading environments such as OSGi, this class is effectively superseded by SimpleDriverDataSource due to general class loading issues with the JDBC DriverManager that be resolved through direct Driver usage (which is exactly what SimpleDriverDataSource does).

If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).

  • 上記にも記載してありますが、DriverManagerDataSourceはテスト用で、 コネクションプールしない と書かれてあります。

これが原因でした

コネクションプールを使用したい場合は、DBCP or C3P0などを使ってくれってことですね。

DBCPやC3P0を使おう

結果

  • 今回はDBCPを使って、コネクションプールを実現しました。
  • スループットは30/secから想定どおりの150/secあたりまで出てくれたのでメデタシメデタシ
4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3