Browse Source

Multiplied the length of the back pressure queue by the max # of queries per request. This should prevent failures from occurring sooner.

Christopher Hunt 12 years ago
parent
commit
5588f6a78f

+ 7 - 6
play-java/app/controllers/Application.java

@@ -26,6 +26,7 @@ import java.util.concurrent.*;
 
 
 public class Application extends Controller {
 public class Application extends Controller {
 
 
+    private static final int MAX_QUERIES_PER_REQUEST = 20;
     private static final int TEST_DATABASE_ROWS = 10000;
     private static final int TEST_DATABASE_ROWS = 10000;
     //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
     //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@@ -43,14 +44,14 @@ public class Application extends Controller {
     private static final ExecutionContext dbEc = ExecutionContexts.fromExecutorService(tpe);
     private static final ExecutionContext dbEc = ExecutionContexts.fromExecutorService(tpe);
 
 
     // A predicate for checking our ability to service database requests is determined by ensuring that the request
     // A predicate for checking our ability to service database requests is determined by ensuring that the request
-    // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections
-    // to determine this threshold. It is a rough check as we don't know how many queries we're going
-    // to make or what other threads are running in parallel etc. Nevertheless, the check is adequate in order to
-    // throttle the acceptance of requests to the size of the pool.
+    // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections * the max
+    // # of db requests per web request to determine this threshold. It is a rough check as we don't know how many
+    // queries we're going to make or what other threads are running in parallel etc. Nevertheless, the check is
+    // adequate in order to throttle the acceptance of requests to the size of the pool.
     public static class IsDbAvailable implements Predicate {
     public static class IsDbAvailable implements Predicate {
         @Override
         @Override
         public boolean condition() {
         public boolean condition() {
-            return (tpe.getQueue().size() < maxConnections);
+            return (tpe.getQueue().size() < maxConnections * MAX_QUERIES_PER_REQUEST);
         }
         }
     }
     }
 
 
@@ -77,7 +78,7 @@ public class Application extends Controller {
                                     findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
                                     findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
                             promises.add(p);
                             promises.add(p);
                         }
                         }
-                        final List<World> worlds = F.Promise.sequence(promises).get(5L * queries, TimeUnit.SECONDS);
+                        final List<World> worlds = F.Promise.sequence(promises).get();
                         return ok(Json.toJson(worlds));
                         return ok(Json.toJson(worlds));
                     }
                     }
 
 

+ 1 - 1
play-java/conf/application.conf

@@ -35,7 +35,7 @@ db.default.user=benchmarkdbuser
 db.default.password=benchmarkdbpass
 db.default.password=benchmarkdbpass
 db.default.jndiName=DefaultDS
 db.default.jndiName=DefaultDS
 
 
-db.default.partitionCount=64
+db.default.partitionCount=4
 
 
 # The number of connections to create per partition. Setting this to 
 # The number of connections to create per partition. Setting this to 
 # 5 with 3 partitions means you will have 15 unique connections to the 
 # 5 with 3 partitions means you will have 15 unique connections to the 

+ 6 - 5
play-scala/app/controllers/Application.scala

@@ -14,6 +14,7 @@ import play.core.NamedThreadFactory
 
 
 object Application extends Controller {
 object Application extends Controller {
 
 
+  private val MaxQueriesPerRequest = 20
   private val TestDatabaseRows = 10000
   private val TestDatabaseRows = 10000
 
 
   private val partitionCount = current.configuration.getInt("db.default.partitionCount").getOrElse(2)
   private val partitionCount = current.configuration.getInt("db.default.partitionCount").getOrElse(2)
@@ -29,11 +30,11 @@ object Application extends Controller {
   private val dbEc = ExecutionContext.fromExecutorService(tpe)
   private val dbEc = ExecutionContext.fromExecutorService(tpe)
 
 
   // A predicate for checking our ability to service database requests is determined by ensuring that the request
   // A predicate for checking our ability to service database requests is determined by ensuring that the request
-  // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections
-  // to determine this threshold. It is a rough check as we don't know how many queries we're going
-  // to make or what other threads are running in parallel etc. Nevertheless, the check is adequate in order to
-  // throttle the acceptance of requests to the size of the pool.
-  def isDbAvailable: Boolean = (tpe.getQueue.size() < maxConnections)
+  // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections * the max
+  // # of db requests per web request to determine this threshold. It is a rough check as we don't know how many
+  // queries we're going to make or what other threads are running in parallel etc. Nevertheless, the check is
+  // adequate in order to throttle the acceptance of requests to the size of the pool.
+  def isDbAvailable: Boolean = (tpe.getQueue.size() < maxConnections * MaxQueriesPerRequest)
 
 
 
 
   def json() = Action {
   def json() = Action {

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

@@ -30,13 +30,12 @@ application.langs="en"
 # You can expose this datasource via JNDI if needed (Useful for JPA)
 # You can expose this datasource via JNDI if needed (Useful for JPA)
 # db.default.jndiName=DefaultDS
 # db.default.jndiName=DefaultDS
 db.default.driver= com.mysql.jdbc.Driver
 db.default.driver= com.mysql.jdbc.Driver
-db.default.url="jdbc:mysql://172.16.98.98:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true"
-#db.default.url="jdbc:mysql://172.16.98.98:3306/hello_world"
+db.default.url="jdbc:mysql://localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true"
 db.default.user=benchmarkdbuser
 db.default.user=benchmarkdbuser
 db.default.password=benchmarkdbpass
 db.default.password=benchmarkdbpass
 db.default.jndiName=DefaultDS
 db.default.jndiName=DefaultDS
 
 
-db.default.partitionCount=64
+db.default.partitionCount=4
 
 
 # The number of connections to create per partition. Setting this to 
 # The number of connections to create per partition. Setting this to 
 # 5 with 3 partitions means you will have 15 unique connections to the 
 # 5 with 3 partitions means you will have 15 unique connections to the