-
Notifications
You must be signed in to change notification settings - Fork 7
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
Hikari pool implementation in perfservice #109
base: main
Are you sure you want to change the base?
Changes from all commits
89a59e7
a23f0d9
9610f39
909f47e
ac90759
084806c
42c12a6
06aeb8e
b38f5ba
3ca3566
e7d7efb
b844ad5
f1f195b
3bfaf90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
@@ -73,15 +75,24 @@ public abstract class BenchmarkModule { | |
public BenchmarkModule(WorkloadConfiguration workConf) { | ||
this.workConf = workConf; | ||
this.dialects = new StatementDialects(workConf); | ||
if (workConf.getXmlConfig().getBoolean("use_hikari_pool", false)) { | ||
try { | ||
createDataSource(); | ||
} catch (Exception e) { | ||
LOG.error("Failed to create Data Source", e); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
// -------------------------------------------------------------------------- | ||
// DATABASE CONNECTION | ||
// -------------------------------------------------------------------------- | ||
|
||
public final Connection makeConnection() throws SQLException { | ||
|
||
if (StringUtils.isEmpty(workConf.getUsername())) { | ||
if (workConf.getXmlConfig().getBoolean("use_hikari_pool", false)) { | ||
return hikariDataSource.getConnection(); | ||
} else if (StringUtils.isEmpty(workConf.getUsername())) { | ||
return DriverManager.getConnection(workConf.getUrl()); | ||
} else { | ||
return DriverManager.getConnection( | ||
|
@@ -91,6 +102,28 @@ public final Connection makeConnection() throws SQLException { | |
} | ||
} | ||
|
||
protected HikariDataSource hikariDataSource; | ||
|
||
public void createDataSource() { | ||
HikariConfig config = new HikariConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should shutdown the dataSource and its associated pool after the test is done. You can call datasource.close for the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented closeDataSource() method which will close it in ThreadBench finalizeWorkers() |
||
config.setJdbcUrl(workConf.getUrl()); | ||
if (!StringUtils.isEmpty(workConf.getUsername())) { | ||
config.setUsername(workConf.getUsername()); | ||
config.setPassword(workConf.getPassword()); | ||
/* take max_pool_size from xmlConfig, default is = number of terminals*/ | ||
config.setMaximumPoolSize(workConf.getXmlConfig().getInt("max_pool_size", workConf.getTerminals())); | ||
config.setMinimumIdle(5); | ||
} | ||
config.setTransactionIsolation(workConf.getIsolationString()); | ||
hikariDataSource = new HikariDataSource(config); | ||
} | ||
|
||
public void closeDataSource() { | ||
if (workConf.getXmlConfig().getBoolean("use_hikari_pool", false)) { | ||
this.hikariDataSource.close(); | ||
} | ||
} | ||
|
||
// -------------------------------------------------------------------------- | ||
// IMPLEMENTING CLASS INTERFACE | ||
// -------------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since worker inherits from benchmarkmodule are we creating one hikari pool per worker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though worker inherits from benchmarkmodule, the datasource is created in benchmarkmodule's constructor which is called only once. Hence, there is only one hikari pool.