Skip to content

Commit

Permalink
Multiplied the length of the back pressure queue by the max # of quer…
Browse files Browse the repository at this point in the history
…ies per request. This should prevent failures from occurring sooner.
  • Loading branch information
huntc committed Apr 17, 2013
1 parent 8407b02 commit b15f828
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
13 changes: 7 additions & 6 deletions play-java/app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand All @@ -77,7 +78,7 @@ public Result call() {
findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
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));
}

Expand Down
2 changes: 1 addition & 1 deletion play-java/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions play-scala/app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions play-scala/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b15f828

Please sign in to comment.