|
@@ -7,9 +7,7 @@ import java.util.concurrent.Executors
|
|
|
import akka.actor.ActorSystem
|
|
|
import com.typesafe.akka.http.benchmark.entity.{Fortune, World}
|
|
|
import com.typesafe.config.Config
|
|
|
-import org.apache.commons.dbcp2.{DriverManagerConnectionFactory, PoolableConnection, PoolableConnectionFactory, PoolingDataSource}
|
|
|
-import org.apache.commons.pool2.impl.GenericObjectPool
|
|
|
-
|
|
|
+import com.zaxxer.hikari._
|
|
|
import scala.concurrent.{ExecutionContext, Future, Promise}
|
|
|
|
|
|
class MySqlDataStore(components: {
|
|
@@ -18,23 +16,13 @@ class MySqlDataStore(components: {
|
|
|
}) extends DataStore {
|
|
|
val config = components.config.getConfig("akka.http.benchmark.mysql")
|
|
|
|
|
|
- private val dataSource: PoolingDataSource[PoolableConnection] = {
|
|
|
- val jdbcUrl = config.getString("jdbc-url")
|
|
|
- val props = new Properties()
|
|
|
- props.setProperty("user", config.getString("dbuser"))
|
|
|
- props.setProperty("password", config.getString("dbpass"))
|
|
|
-
|
|
|
- val connectionFactory = new DriverManagerConnectionFactory(jdbcUrl, props)
|
|
|
- val poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null)
|
|
|
- val connectionPool = new GenericObjectPool[PoolableConnection](poolableConnectionFactory)
|
|
|
- connectionPool.setTestOnBorrow(true)
|
|
|
- connectionPool.setMinIdle(config.getString("min-idle").toInt)
|
|
|
- connectionPool.setMaxIdle(config.getString("max-idle").toInt)
|
|
|
- connectionPool.setMaxTotal(config.getString("max-total").toInt)
|
|
|
- poolableConnectionFactory.setPool(connectionPool)
|
|
|
- poolableConnectionFactory.setValidationQuery("select 1")
|
|
|
- new PoolingDataSource[PoolableConnection](connectionPool)
|
|
|
+ private val dataSource = new HikariDataSource {
|
|
|
+ setJdbcUrl(config.getString("jdbc-url"))
|
|
|
+ setUsername(config.getString("dbuser"))
|
|
|
+ setPassword(config.getString("dbpass"))
|
|
|
+ setMaximumPoolSize(config.getInt("connection-pool-size"))
|
|
|
}
|
|
|
+
|
|
|
private implicit val executionContext: ExecutionContext = {
|
|
|
val size = config.getInt("thread-pool-size")
|
|
|
val threadPool = Executors.newFixedThreadPool(size)
|