Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Hikari Connection Pool for using only YSQL Connection Manager #157

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
59 changes: 59 additions & 0 deletions config/workload_all_conn_mngr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<parameters>
<dbtype>yugabyte</dbtype>
<driver>com.yugabyte.Driver</driver>
<port>5433</port>
<username>yugabyte</username>
<DBName>yugabyte</DBName>
<password></password>
<isolation>TRANSACTION_REPEATABLE_READ</isolation>

<sslCert></sslCert>
<sslKey></sslKey>
<jdbcURL></jdbcURL>

<useHikariPool>false</useHikariPool>
<createConnForEveryTx>false</createConnForEveryTx>

<batchSize>128</batchSize>
<useKeyingTime>true</useKeyingTime>
<useThinkTime>true</useThinkTime>
<enableForeignKeysAfterLoad>true</enableForeignKeysAfterLoad>
<hikariConnectionTimeoutMs>180000</hikariConnectionTimeoutMs>
<useStoredProcedures>true</useStoredProcedures>
<displayEnhancedLatencyMetrics>false</displayEnhancedLatencyMetrics>
<trackPerSQLStmtLatencies>false</trackPerSQLStmtLatencies>

<transactiontypes>
<transaction>
<name>NewOrder</name>
<weight>45</weight>
</transaction>
<transaction>
<name>Payment</name>
<weight>43</weight>
</transaction>
<transaction>
<name>OrderStatus</name>
<weight>4</weight>
</transaction>
<transaction>
<name>Delivery</name>
<weight>4</weight>
</transaction>
<transaction>
<name>StockLevel</name>
<weight>4</weight>
</transaction>
</transactiontypes>

<runtime>1800</runtime>
<rate>10000</rate>
<!--
Set the number of retries to 0 as retrying when the number of warehouses is
high is pointless as it just leads to more failures.
-->
<maxRetriesPerTransaction>2</maxRetriesPerTransaction>
<maxLoaderRetries>2</maxLoaderRetries>

</parameters>
59 changes: 59 additions & 0 deletions config/workload_all_conn_newConn_everyTxn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<parameters>
<dbtype>yugabyte</dbtype>
<driver>com.yugabyte.Driver</driver>
<port>5433</port>
<username>yugabyte</username>
<DBName>yugabyte</DBName>
<password></password>
<isolation>TRANSACTION_REPEATABLE_READ</isolation>

<sslCert></sslCert>
<sslKey></sslKey>
<jdbcURL></jdbcURL>

<useHikariPool>false</useHikariPool>
<createConnForEveryTx>true</createConnForEveryTx>

<batchSize>128</batchSize>
<useKeyingTime>true</useKeyingTime>
<useThinkTime>true</useThinkTime>
<enableForeignKeysAfterLoad>true</enableForeignKeysAfterLoad>
<hikariConnectionTimeoutMs>180000</hikariConnectionTimeoutMs>
<useStoredProcedures>true</useStoredProcedures>
<displayEnhancedLatencyMetrics>false</displayEnhancedLatencyMetrics>
<trackPerSQLStmtLatencies>false</trackPerSQLStmtLatencies>

<transactiontypes>
<transaction>
<name>NewOrder</name>
<weight>45</weight>
</transaction>
<transaction>
<name>Payment</name>
<weight>43</weight>
</transaction>
<transaction>
<name>OrderStatus</name>
<weight>4</weight>
</transaction>
<transaction>
<name>Delivery</name>
<weight>4</weight>
</transaction>
<transaction>
<name>StockLevel</name>
<weight>4</weight>
</transaction>
</transactiontypes>

<runtime>1800</runtime>
<rate>10000</rate>
<!--
Set the number of retries to 0 as retrying when the number of warehouses is
high is pointless as it just leads to more failures.
-->
<maxRetriesPerTransaction>2</maxRetriesPerTransaction>
<maxLoaderRetries>2</maxLoaderRetries>

</parameters>
1 change: 0 additions & 1 deletion src/com/oltpbenchmark/BenchmarkState.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void ackLatencyComplete() {
public void startCoolDown() {
assert state == State.MEASURE;
state = State.DONE;

// The master thread must also signal that it is done
signalDone();
}
Expand Down
8 changes: 8 additions & 0 deletions src/com/oltpbenchmark/ConfigFileOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public Optional<Boolean> getUseThinkTime() {
return getBoolOpt("useThinkTime");
}

public Optional<Boolean> getUseHikariPool() {
return getBoolOpt("useHikariPool");
}

public Optional<Boolean> getCreateConnForEveryTx() {
return getBoolOpt("createConnForEveryTx");
}

public Optional<Boolean> getEnableForeignKeysAfterLoad() {
return getBoolOpt("enableForeignKeysAfterLoad");
}
Expand Down
2 changes: 2 additions & 0 deletions src/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ public static void main(String[] args) throws Exception {
wrkld.setShouldEnableForeignKeys(false);
}

configOptions.getUseHikariPool().ifPresent(wrkld::setUseHikariPool);
configOptions.getCreateConnForEveryTx().ifPresent(wrkld::setUseCreateConnForEveryTx);
configOptions.getBatchSize().ifPresent(wrkld::setBatchSize);
configOptions.getMaxRetriesPerTransaction().ifPresent(wrkld::setMaxRetriesPerTransaction);
configOptions.getMaxLoaderRetries().ifPresent(wrkld::setMaxLoaderRetries);
Expand Down
1 change: 1 addition & 0 deletions src/com/oltpbenchmark/ThreadBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ private int finalizeWorkers(ArrayList<Thread> workerThreads) throws InterruptedE
*/

requests += w.getRequests();
w.closeConnection();
}
testState = null;
return requests;
Expand Down
12 changes: 12 additions & 0 deletions src/com/oltpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public void setBenchmarkName(String benchmarkName) {
private boolean useStoredProcedures = true;
private int maxRetriesPerTransaction = 0;
private int maxLoaderRetries = 0;
private boolean useHikariPool = true;
private boolean useCreateConnForEveryTx = false;

public TraceReader getTraceReader() {
return traceReader;
Expand Down Expand Up @@ -361,6 +363,16 @@ public void setMaxRetriesPerTransaction(int maxRetriesPerTransaction) {
this.maxRetriesPerTransaction = maxRetriesPerTransaction;
}

public void setUseHikariPool(boolean useHikariPool) {
this.useHikariPool = useHikariPool;
}
public boolean getUseHikariPool() { return this.useHikariPool; }

public void setUseCreateConnForEveryTx(boolean useCreateConnForEveryTx) {
this.useCreateConnForEveryTx = useCreateConnForEveryTx;
}
public boolean getUseCreateConnForEveryTx() { return this.useCreateConnForEveryTx; }

public int getMaxRetriesPerTransaction() {
return maxRetriesPerTransaction;
}
Expand Down
5 changes: 4 additions & 1 deletion src/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public BenchmarkModule(WorkloadConfiguration workConf) {
this.workConf = workConf;
if (workConf.getNeedsExecution()) {
try {
createDataSource();
if(workConf.getUseHikariPool())
createDataSource();
else
LOG.info("Hikari Connection Pool is disabled");
} catch (Exception e) {
LOG.error("Failed to create Data source", e);
throw e;
Expand Down
34 changes: 27 additions & 7 deletions src/com/oltpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ public class Worker implements Runnable {
private TransactionLatencyRecord latencies;
private TransactionLatencyRecord failureLatencies;
private WorkerTaskLatencyRecord workerTaskLatencyRecord;

private final Statement currStatement;

// Interval requests used by the monitor
private final AtomicInteger intervalRequests = new AtomicInteger(0);

private final Connection ll_conn;
sonalsagarwal marked this conversation as resolved.
Show resolved Hide resolved
private final int id;
private final BenchmarkModule benchmarkModule;
protected final HikariDataSource dataSource;
Expand All @@ -81,7 +80,13 @@ public Worker(

assert (this.transactionTypes != null) : "The TransactionTypes from the WorkloadConfiguration is null!";
try {
this.dataSource = this.benchmarkModule.getDataSource();
if(!wrkld.getUseHikariPool()) {
this.dataSource = null;
ll_conn = wrkld.getUseCreateConnForEveryTx() ? null : benchmarkModule.makeConnection();
} else { //use Hikari Pool
ll_conn = null;
this.dataSource = this.benchmarkModule.getDataSource();
}
} catch (Exception ex) {
throw new RuntimeException("Failed to connect to database", ex);
}
Expand Down Expand Up @@ -215,6 +220,15 @@ synchronized public void cancelStatement() {
}
}

public void closeConnection() {
try {
if(ll_conn != null)
ll_conn.close();
} catch (SQLException e) {
LOG.error("Failed to close connection: " + e.getMessage());
}
}

public void test(Connection conn) throws Exception {
Procedure proc = this.getProcedure(
this.transactionTypes.getType("NewOrder").getProcedureClass());
Expand Down Expand Up @@ -479,8 +493,10 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
next = transactionTypes.getType(pieceOfWork.getType());
}
startConnection = System.nanoTime();

conn = dataSource.getConnection();
if( !wrkld.getUseHikariPool()) {
conn = wrkld.getUseCreateConnForEveryTx() ? benchmarkModule.makeConnection() : ll_conn;
} else //use Hikari connection Pool
conn = dataSource.getConnection();
try {
if(wrkld.getDBType().equals("yugabyte"))
conn.createStatement().execute("SET yb_enable_expression_pushdown to on");
Expand All @@ -490,7 +506,7 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
conn.setAutoCommit(false);
}
} catch (Throwable e) {

LOG.info("Error in enabling expression_pushdown or setting auto_commit to false");
}

endConnection = System.nanoTime();
Expand Down Expand Up @@ -592,7 +608,11 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
break;
}
} // WHILE
conn.close();
if(!wrkld.getUseHikariPool()) {
if (wrkld.getUseCreateConnForEveryTx())
conn.close();
} else
conn.close();
sonalsagarwal marked this conversation as resolved.
Show resolved Hide resolved
} catch (SQLException ex) {
String msg = String.format("Unexpected fatal, error in '%s' when executing '%s'",
this, next);
Expand Down