Browse Source

Beginnings of connection pooling configuration.

Christopher Hunt 12 years ago
parent
commit
b8c88f18dc

+ 5 - 0
play-java/app/controllers/Application.java

@@ -1,6 +1,7 @@
 package controllers;
 
 import models.World;
+import play.libs.Akka;
 import play.libs.F;
 import play.libs.Json;
 
@@ -10,6 +11,7 @@ import org.codehaus.jackson.node.ObjectNode;
 import org.codehaus.jackson.map.ObjectMapper;
 import play.mvc.Controller;
 import play.mvc.Result;
+import scala.concurrent.ExecutionContext;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -24,6 +26,8 @@ public class Application extends Controller {
     //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
     private static final ObjectMapper objectMapper = new ObjectMapper();
 
+    private static final ExecutionContext dbEc = Akka.system().dispatchers().lookup("db");
+
     public static Result json() {
         final ObjectNode result = objectMapper.createObjectNode();
         result.put("message", "Hello World!");
@@ -38,6 +42,7 @@ public class Application extends Controller {
                         final Random random = ThreadLocalRandom.current();
                         final List<F.Promise<? extends World>> promises = new ArrayList<F.Promise<? extends World>>(queries);
                         for (int i = 0; i < queries; ++i) {
+                            //FIXME: How do we express the use of dbEc here?
                             promises.add(future(findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1))));
                         }
                         final List<World> worlds = F.Promise.sequence(promises).get(5L * queries, TimeUnit.SECONDS);

+ 8 - 0
play-java/conf/application.conf

@@ -87,6 +87,14 @@ play {
           parallelism-max = 300
         }
       }	
+      db {
+        thread-pool-executor {
+          core-pool-size-factor = 1.0
+          core-pool-size-min = 10
+          core-pool-size-max = 10
+        }
+      }
+
     }
   }
 }

+ 4 - 2
play-scala/app/controllers/Application.scala

@@ -1,6 +1,6 @@
 package controllers
 
-import play.api._
+import play.api.Play.current
 import play.api.mvc._
 import play.api.libs.json.Json
 import play.api.libs.concurrent._
@@ -19,12 +19,14 @@ object Application extends Controller {
   def db(queries: Int) = Action {
     import play.api.libs.concurrent.Execution.Implicits._
 
+    val dbEc: ExecutionContext = Akka.system.dispatchers.lookup("db")
+
     Async {
       val random = ThreadLocalRandom.current()
 
       val worlds = Future.sequence( (for {
         _ <- (1 to queries).par
-      } yield Future(World.findById(random.nextInt(TEST_DATABASE_ROWS) + 1))).toList)
+      } yield Future(World.findById(random.nextInt(TEST_DATABASE_ROWS) + 1))(dbEc)).toList)
 
       worlds map {
         w => Ok(Json.toJson(w))  

+ 11 - 3
play-scala/conf/application.conf

@@ -36,17 +36,17 @@ db.default.user=benchmarkdbuser
 db.default.password=benchmarkdbpass
 db.default.jndiName=DefaultDS
 
-db.default.partitionCount=2
+db.default.partitionCount=3
 
 # The number of connections to create per partition. Setting this to 
 # 5 with 3 partitions means you will have 15 unique connections to the 
 # database. Note that BoneCP will not create all these connections in 
 # one go but rather start off with minConnectionsPerPartition and 
 # gradually increase connections as required.
-db.default.maxConnectionsPerPartition=5
+db.default.maxConnectionsPerPartition=800
 
 # The number of initial connections, per partition.
-db.default.minConnectionsPerPartition=5
+db.default.minConnectionsPerPartition=10
 
 # Evolutions
 # ~~~~~
@@ -82,6 +82,14 @@ play {
           parallelism-max = 300
         }
       }
+      db {
+        thread-pool-executor {
+          core-pool-size-factor = 1.0
+          core-pool-size-min = 100
+          core-pool-size-max = 100
+        }
+      }
+
     }
   }
 }