55import io .avaje .config .Config ;
66import io .avaje .inject .Bean ;
77import io .avaje .inject .Factory ;
8+ import java .util .concurrent .Executors ;
89import 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}
0 commit comments