diff --git a/play-java/app/controllers/Application.java b/play-java/app/controllers/Application.java index 4fc12ae51cd..a7c4e5184da 100644 --- a/play-java/app/controllers/Application.java +++ b/play-java/app/controllers/Application.java @@ -26,6 +26,7 @@ public class Application extends Controller { + private static final int MAX_QUERIES_PER_REQUEST = 20; private static final int TEST_DATABASE_ROWS = 10000; //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final 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); // 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 { @Override public boolean condition() { - return (tpe.getQueue().size() < maxConnections); + return (tpe.getQueue().size() < maxConnections * MAX_QUERIES_PER_REQUEST); } } @@ -77,7 +78,7 @@ public Result call() { findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc)); promises.add(p); } - final List worlds = F.Promise.sequence(promises).get(5L * queries, TimeUnit.SECONDS); + final List worlds = F.Promise.sequence(promises).get(); return ok(Json.toJson(worlds)); } diff --git a/play-java/conf/application.conf b/play-java/conf/application.conf index c3796d2979e..b30b61312ea 100644 --- a/play-java/conf/application.conf +++ b/play-java/conf/application.conf @@ -35,7 +35,7 @@ db.default.user=benchmarkdbuser db.default.password=benchmarkdbpass db.default.jndiName=DefaultDS -db.default.partitionCount=64 +db.default.partitionCount=4 # The number of connections to create per partition. Setting this to # 5 with 3 partitions means you will have 15 unique connections to the diff --git a/play-scala/app/controllers/Application.scala b/play-scala/app/controllers/Application.scala index 7aa83b2429c..cb43ae0cc29 100644 --- a/play-scala/app/controllers/Application.scala +++ b/play-scala/app/controllers/Application.scala @@ -14,6 +14,7 @@ import play.core.NamedThreadFactory object Application extends Controller { + private val MaxQueriesPerRequest = 20 private val TestDatabaseRows = 10000 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) // 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 { diff --git a/play-scala/conf/application.conf b/play-scala/conf/application.conf index 687b7bbbae2..172edd57274 100644 --- a/play-scala/conf/application.conf +++ b/play-scala/conf/application.conf @@ -30,13 +30,12 @@ application.langs="en" # You can expose this datasource via JNDI if needed (Useful for JPA) # db.default.jndiName=DefaultDS 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.password=benchmarkdbpass db.default.jndiName=DefaultDS -db.default.partitionCount=64 +db.default.partitionCount=4 # The number of connections to create per partition. Setting this to # 5 with 3 partitions means you will have 15 unique connections to the