From 53e8658d74604acaf6e3b959f2431c31f7c0d867 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sat, 28 Mar 2020 15:06:15 +0100 Subject: [PATCH] apply Hikari's recommended MySQL Configuration (FINERACT-796) from https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration and https://github.com/brettwooldridge/HikariCP/wiki/JDBC-Logging#mysql-connectorj --- .../TomcatJdbcDataSourcePerTenantService.java | 21 +++++++++++++++++++ .../META-INF/spring/hikariDataSource.xml | 13 ++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java index 48a2bbb56..71be36e66 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/TomcatJdbcDataSourcePerTenantService.java @@ -86,11 +86,32 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe config.setJdbcUrl(jdbcUrl); config.setUsername(tenantConnectionObj.getSchemaUsername()); config.setPassword(tenantConnectionObj.getSchemaPassword()); + config.setMinimumIdle(tenantConnectionObj.getInitialSize()); + config.setMaximumPoolSize(tenantConnectionObj.getMaxActive()); config.setConnectionTestQuery("SELECT 1"); config.setValidationTimeout(tenantConnectionObj.getValidationInterval()); config.setAutoCommit(true); + // https://github.com/brettwooldridge/HikariCP/wiki/MBean-(JMX)-Monitoring-and-Management + config.setRegisterMbeans(true); + // https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration + // These are the properties for each Tenant DB; the same configuration is also in src/main/resources/META-INF/spring/hikariDataSource.xml for the all Tenants DB --> + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + config.addDataSourceProperty("useServerPrepStmts", "true"); + config.addDataSourceProperty("useLocalSessionState", "true"); + config.addDataSourceProperty("rewriteBatchedStatements", "true"); + config.addDataSourceProperty("cacheResultSetMetadata", "true"); + config.addDataSourceProperty("cacheServerConfiguration", "true"); + config.addDataSourceProperty("elideSetAutoCommits", "true"); + config.addDataSourceProperty("maintainTimeStats", "false"); + + // https://github.com/brettwooldridge/HikariCP/wiki/JDBC-Logging#mysql-connectorj + config.addDataSourceProperty("logger", "com.mysql.jdbc.log.StandardLogger"); + config.addDataSourceProperty("logSlowQueries", "true"); + config.addDataSourceProperty("dumpQueriesOnException", "true"); return new HikariDataSource(config); } diff --git a/fineract-provider/src/main/resources/META-INF/spring/hikariDataSource.xml b/fineract-provider/src/main/resources/META-INF/spring/hikariDataSource.xml index 1ee210897..1ba0ba029 100644 --- a/fineract-provider/src/main/resources/META-INF/spring/hikariDataSource.xml +++ b/fineract-provider/src/main/resources/META-INF/spring/hikariDataSource.xml @@ -44,21 +44,26 @@ - + + true 250 2048 true true - true true true true - true + false + + + com.mysql.jdbc.log.StandardLogger + true + true - +