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あたりまで出てくれたのでメデタシメデタシ