Skip to content

Commit b1fe6ec

Browse files
committed
tweak hikari
1 parent a40500b commit b1fe6ec

3 files changed

Lines changed: 25 additions & 14 deletions

File tree

frameworks/Java/avaje-jex/src/main/java/benchmark/repository/HikariFactory.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.avaje.config.Config;
66
import io.avaje.inject.Bean;
77
import io.avaje.inject.Factory;
8+
import java.util.concurrent.Executors;
89
import javax.sql.DataSource;
910

1011
@Factory
@@ -22,8 +23,21 @@ DataSource dataSource() {
2223
maxPoolSize = Config.getInt("postgresDefaultPoolSize");
2324
}
2425

25-
var hikari = new HikariDataSource(new HikariConfig("hikari.properties"));
26-
hikari.setMaximumPoolSize(maxPoolSize);
27-
return hikari;
26+
maxPoolSize = Math.max(maxPoolSize, Runtime.getRuntime().availableProcessors() * 2);
27+
HikariConfig hikariConfig = new HikariConfig("hikari.properties");
28+
29+
var vtThreadFactory = Thread.ofVirtual().factory();
30+
hikariConfig.setThreadFactory(vtThreadFactory);
31+
hikariConfig.setScheduledExecutor(
32+
Executors.newScheduledThreadPool(maxPoolSize, vtThreadFactory));
33+
34+
// data source properties
35+
hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
36+
hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
37+
hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
38+
hikariConfig.addDataSourceProperty("ssl", "false");
39+
hikariConfig.addDataSourceProperty("tcpKeepAlive", "true");
40+
hikariConfig.setMaximumPoolSize(maxPoolSize);
41+
return new HikariDataSource(hikariConfig);
2842
}
2943
}

frameworks/Java/avaje-jex/src/main/java/benchmark/repository/JDBCDbService.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@ public JDBCDbService(DataSource connectionFactory) {
2222
}
2323

2424
@Override
25-
public List<World> getWorld(int num) {
25+
public List<World> getWorld(int num) throws SQLException {
2626

27-
String select = "select id, randomNumber from World where id = ?";
27+
String select = "select id, randomNumber from World where id IN (?)";
2828
List<World> worldList = new ArrayList<>();
2929

3030
try (Connection conn = datasource.getConnection();
3131
PreparedStatement pstm = conn.prepareStatement(select)) {
3232

33-
for (int randomId : getRandomNumberSet(num)) {
34-
pstm.setInt(1, randomId);
35-
try (ResultSet rs = pstm.executeQuery()) {
36-
rs.next();
37-
worldList.add(new World(rs.getInt("id"), rs.getInt("randomNumber")));
33+
pstm.setObject(1, getRandomNumberSet(num));
34+
try (ResultSet rs = pstm.executeQuery()) {
35+
while (rs.next()) {
36+
worldList.add(new World(rs.getInt(0), rs.getInt(1)));
3837
}
3938
}
40-
} catch (SQLException e) {
41-
throw new RuntimeException(e);
4239
}
4340

4441
return worldList;
@@ -55,7 +52,7 @@ public List<Fortune> getFortune() throws SQLException {
5552
ResultSet rs = pstm.executeQuery()) {
5653

5754
while (rs.next()) {
58-
fortuneList.add(new Fortune(rs.getInt("id"), rs.getString("message")));
55+
fortuneList.add(new Fortune(rs.getInt(1), rs.getString(2)));
5956
}
6057
fortuneList.add(new Fortune(defaultFortuneId, defaultFortuneMessage));
6158
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
physicalTag=Citrine
22
cloudTag=Azure
33

4-
postgresPhysicalPoolSize=56
4+
postgresPhysicalPoolSize=64
55
postgresCloudPoolSize=16
66
postgresDefaultPoolSize=10

0 commit comments

Comments
 (0)