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
2 changes: 2 additions & 0 deletions config/workload_all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<sslCert></sslCert>
<sslKey></sslKey>
<jdbcURL></jdbcURL>
<useConnMngr>false</useConnMngr>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useConnMngr --> useHikariPool

<useShortLivedConn>false</useShortLivedConn>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useShortLivedConn --> createConnForEveryTx


<batchSize>128</batchSize>
<useKeyingTime>true</useKeyingTime>
Expand Down
58 changes: 58 additions & 0 deletions config/workload_all_conn_mngr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>
<useConnMngr>true</useConnMngr>
<useShortLivedConn>false</useShortLivedConn>

<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>
58 changes: 58 additions & 0 deletions config/workload_all_conn_mngr_short_lived_conn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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>
<useConnMngr>true</useConnMngr>
<useShortLivedConn>true</useShortLivedConn>

<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>
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> getUseConnMngr() {
return getBoolOpt("useConnMngr");
}

public Optional<Boolean> getUseShortLivedConn() {
return getBoolOpt("useShortLivedConn");
}

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.getUseConnMngr().ifPresent(wrkld::setUseConnMngr);
configOptions.getUseShortLivedConn().ifPresent(wrkld::setUseShortLivedConn);
configOptions.getBatchSize().ifPresent(wrkld::setBatchSize);
configOptions.getMaxRetriesPerTransaction().ifPresent(wrkld::setMaxRetriesPerTransaction);
configOptions.getMaxLoaderRetries().ifPresent(wrkld::setMaxLoaderRetries);
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 useConnMngr;
private boolean useShortLivedConn;

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

public void setUseConnMngr(boolean useConnMngr) {
this.useConnMngr = useConnMngr;
}
public boolean getUseConnMngr() { return this.useConnMngr; }

public void setUseShortLivedConn(boolean useShortLivedConn) {
this.useShortLivedConn = useShortLivedConn;
}
public boolean getUseShortLivedConn() { return this.useShortLivedConn; }

public int getMaxRetriesPerTransaction() {
return maxRetriesPerTransaction;
}
Expand Down
6 changes: 5 additions & 1 deletion src/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public BenchmarkModule(WorkloadConfiguration workConf) {
this.workConf = workConf;
if (workConf.getNeedsExecution()) {
try {
createDataSource();
if(!workConf.getUseConnMngr())
createDataSource();
else {
System.out.println("Using connection manager without HikariPool");
}
} catch (Exception e) {
LOG.error("Failed to create Data source", e);
throw e;
Expand Down
32 changes: 24 additions & 8 deletions src/com/oltpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.oltpbenchmark.api;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.*;
Expand Down Expand Up @@ -51,12 +52,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 Connection ll_conn;
private final int id;
private final BenchmarkModule benchmarkModule;
protected final HikariDataSource dataSource;
Expand All @@ -81,7 +81,15 @@ public Worker(

assert (this.transactionTypes != null) : "The TransactionTypes from the WorkloadConfiguration is null!";
try {
this.dataSource = this.benchmarkModule.getDataSource();
if(wrkld.getUseConnMngr()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very confusing and hard to read code

if (connManager && shortLivedConnections)
{
this.dataSource = null;
ll_conn = null;
}
else if (connManager && !shortLivedConnections) {
this.dataSource = null;
ll_conn = benchmarkModule.makeConnection();;
}
else {
this.dataSource = this.benchmarkModule.getDataSource();;
ll_conn = null;

}

this.dataSource = null;
if(!wrkld.getUseShortLivedConn()) {
ll_conn = benchmarkModule.makeConnection();
System.out.println("Using connection manager for long lived connection without HikariPool");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont use System.out.println

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just for debugging purpose

}
} else {
this.dataSource = this.benchmarkModule.getDataSource();
}
} catch (Exception ex) {
throw new RuntimeException("Failed to connect to database", ex);
}
Expand Down Expand Up @@ -473,14 +481,18 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do

TransactionStatus status = TransactionStatus.RETRY;

Connection conn;
Connection conn = ll_conn;
try {
if (next == null) {
next = transactionTypes.getType(pieceOfWork.getType());
}
startConnection = System.nanoTime();

conn = dataSource.getConnection();
if(wrkld.getUseConnMngr()){
if(wrkld.getUseShortLivedConn())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (connManager && shortLivedConnections)
{
conn = benchmarkModule.makeConnection();
}
else if (connManager && !shortLivedConnections) {

conn = ll_conn;

}
else {
conn = conn = dataSource.getConnection();
}

conn = benchmarkModule.makeConnection();
} else {
conn = dataSource.getConnection();
}
try {
if(wrkld.getDBType().equals("yugabyte"))
conn.createStatement().execute("SET yb_enable_expression_pushdown to on");
Expand All @@ -490,7 +502,7 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
conn.setAutoCommit(false);
}
} catch (Throwable e) {

System.out.println("Error in enabling expression_pushdown or setting auto_commit to false ");
}

endConnection = System.nanoTime();
Expand Down Expand Up @@ -592,7 +604,11 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
break;
}
} // WHILE
conn.close();
if(wrkld.getUseConnMngr()) {
if (wrkld.getUseShortLivedConn())
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