Skip to content

Commit 155f776

Browse files
authored
[avaje-jex] tweak hikari settings (#9919)
1 parent bcfee4a commit 155f776

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

frameworks/Java/avaje-jex/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>org.postgresql</groupId>
6060
<artifactId>postgresql</artifactId>
61-
<version>42.7.5</version>
61+
<version>42.7.6</version>
6262
</dependency>
6363

6464
<dependency>

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ 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

2727
String select = "select id, randomNumber from World where id = ?";
2828
List<World> worldList = new ArrayList<>();
@@ -37,8 +37,6 @@ public List<World> getWorld(int num) {
3737
worldList.add(new World(rs.getInt("id"), rs.getInt("randomNumber")));
3838
}
3939
}
40-
} catch (SQLException e) {
41-
throw new RuntimeException(e);
4240
}
4341

4442
return worldList;
@@ -55,7 +53,7 @@ public List<Fortune> getFortune() throws SQLException {
5553
ResultSet rs = pstm.executeQuery()) {
5654

5755
while (rs.next()) {
58-
fortuneList.add(new Fortune(rs.getInt("id"), rs.getString("message")));
56+
fortuneList.add(new Fortune(rs.getInt(1), rs.getString(2)));
5957
}
6058
fortuneList.add(new Fortune(defaultFortuneId, defaultFortuneMessage));
6159
}
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

frameworks/Java/avaje-jex/src/main/resources/hikari.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
1+
jdbcUrl=jdbc:postgresql://tfb-database:5432/hello_world
22
dataSource.serverName=tfb-database
33
dataSource.portNumber=5432
44
dataSource.user=benchmarkdbuser

0 commit comments

Comments
 (0)