Browse Source

http4s: Set database pool size to 256 connections.

Gary Coady 9 years ago
parent
commit
70af67543f
1 changed files with 16 additions and 2 deletions
  1. 16 2
      frameworks/Scala/http4s/src/main/scala/WebServer.scala

+ 16 - 2
frameworks/Scala/http4s/src/main/scala/WebServer.scala

@@ -57,8 +57,22 @@ object Queries extends OptionalValidatingQueryParamDecoderMatcher[Int]("queries"
 object WebServer extends TaskApp {
 object WebServer extends TaskApp {
   implicit def jsonEncoder[A](implicit encoder: Encoder[A]) = jsonEncoderOf[A](encoder)
   implicit def jsonEncoder[A](implicit encoder: Encoder[A]) = jsonEncoderOf[A](encoder)
 
 
-  def xaTask(host: String) =
-    HikariTransactor[Task]("org.postgresql.Driver", s"jdbc:postgresql://$host/hello_world", "benchmarkdbuser", "benchmarkdbpass")
+  def xaTask(host: String) = {
+    val driver = "org.postgresql.Driver"
+    val url = s"jdbc:postgresql://$host/hello_world"
+    val user = "benchmarkdbuser"
+    val pass = "benchmarkdbpass"
+    val maxPoolSize = 256
+    val minIdle = 256
+
+    for {
+      xa <- HikariTransactor[Task](driver, url, user, pass)
+      _  <- xa.configure(ds => Task.delay {
+         ds.setMaximumPoolSize(maxPoolSize)
+         ds.setMinimumIdle(minIdle)
+      })
+    } yield xa
+  }
 
 
   // Provide a random number between 1 and 10000 (inclusive)
   // Provide a random number between 1 and 10000 (inclusive)
   val randomWorldId: Task[Int] = Task.delay(ThreadLocalRandom.current.nextInt(1, 10001))
   val randomWorldId: Task[Int] = Task.delay(ThreadLocalRandom.current.nextInt(1, 10001))