From 9fa5f2beea7b267091cb7dabb6d8ae5bd4290ea2 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 2 Sep 2016 15:48:58 +0200 Subject: [PATCH] Mysql CP performance enhancements --- src/main/java/fr/xephi/authme/datasource/MySQL.java | 6 +++++- src/main/java/fr/xephi/authme/util/RuntimeUtils.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/main/java/fr/xephi/authme/util/RuntimeUtils.java diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 661e3fad9..dc08d7b46 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -12,6 +12,7 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.SecuritySettings; +import fr.xephi.authme.util.RuntimeUtils; import fr.xephi.authme.util.StringUtils; import java.sql.Blob; @@ -100,6 +101,9 @@ public class MySQL implements DataSource { ds = new HikariDataSource(); ds.setPoolName("AuthMeMYSQLPool"); + // Pool size + ds.setMaximumPoolSize(RuntimeUtils.getCoreCount()); + // Database URL ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); @@ -118,7 +122,7 @@ public class MySQL implements DataSource { // Caching ds.addDataSourceProperty("cachePrepStmts", "true"); - ds.addDataSourceProperty("prepStmtCacheSize", "250"); + ds.addDataSourceProperty("prepStmtCacheSize", "275"); ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); diff --git a/src/main/java/fr/xephi/authme/util/RuntimeUtils.java b/src/main/java/fr/xephi/authme/util/RuntimeUtils.java new file mode 100644 index 000000000..af7fa3a34 --- /dev/null +++ b/src/main/java/fr/xephi/authme/util/RuntimeUtils.java @@ -0,0 +1,7 @@ +package fr.xephi.authme.util; + +public class RuntimeUtils { + public static int getCoreCount() { + return Runtime.getRuntime().availableProcessors(); + } +}