diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index 46dc25dd..d32b495a 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -295,7 +295,35 @@ data: database: minecraft username: root password: '' - pool-size: 10 # The size of the MySQL connection pool. + + # These settings apply to the MySQL connection pool. + # The default values will be suitable for the majority of users. + # Do not change these settings unless you know what you're doing! + pool-settings: + + # Sets the maximum size of the MySQL connection pool. + # Basically this value will determine the maximum number of actual + # connections to the database backend. + # + # More information about determining the size of connection pools can be found here: + # https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing + maximum-pool-size: 10 + + # Sets the minimum number of idle connections that the pool will try to maintain. + # + # For maximum performance and responsiveness to spike demands, it is recommended to not set + # this value and instead allow the pool to act as a fixed size connection pool. + # (set this value to the same as 'maximum-pool-size') + minimum-idle: 10 + + # This setting controls the maximum lifetime of a connection in the pool in milliseconds. + # The value should be at least 30 seconds less than any database or infrastructure imposed + # connection time limit. + maximum-lifetime: 1800000 # 30 minutes + + # This setting controls the maximum number of milliseconds that the plugin will wait for a + # connection from the pool, before timing out. + connection-timeout: 15000 # 15 seconds # The prefix for all LuckPerms tables. Change this is you want to use different tables for # different servers. diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml index ecd3b251..1d242a4f 100644 --- a/bungee/src/main/resources/config.yml +++ b/bungee/src/main/resources/config.yml @@ -241,7 +241,35 @@ data: database: minecraft username: root password: '' - pool-size: 10 # The size of the MySQL connection pool. + + # These settings apply to the MySQL connection pool. + # The default values will be suitable for the majority of users. + # Do not change these settings unless you know what you're doing! + pool-settings: + + # Sets the maximum size of the MySQL connection pool. + # Basically this value will determine the maximum number of actual + # connections to the database backend. + # + # More information about determining the size of connection pools can be found here: + # https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing + maximum-pool-size: 10 + + # Sets the minimum number of idle connections that the pool will try to maintain. + # + # For maximum performance and responsiveness to spike demands, it is recommended to not set + # this value and instead allow the pool to act as a fixed size connection pool. + # (set this value to the same as 'maximum-pool-size') + minimum-idle: 10 + + # This setting controls the maximum lifetime of a connection in the pool in milliseconds. + # The value should be at least 30 seconds less than any database or infrastructure imposed + # connection time limit. + maximum-lifetime: 1800000 # 30 minutes + + # This setting controls the maximum number of milliseconds that the plugin will wait for a + # connection from the pool, before timing out. + connection-timeout: 15000 # 15 seconds # The prefix for all LuckPerms tables. Change this is you want to use different tables for # different servers. diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 96fc1238..9f29a636 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -48,7 +48,7 @@ import me.lucko.luckperms.common.primarygroup.AllParentsByWeightHolder; import me.lucko.luckperms.common.primarygroup.ParentsByWeightHolder; import me.lucko.luckperms.common.primarygroup.PrimaryGroupHolder; import me.lucko.luckperms.common.primarygroup.StoredHolder; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; import me.lucko.luckperms.common.utils.ImmutableCollectors; import java.lang.reflect.Field; @@ -358,13 +358,17 @@ public class ConfigKeys { /** * The database settings, username, password, etc for use by any database */ - public static final ConfigKey DATABASE_VALUES = EnduringKey.wrap(AbstractKey.of(c -> { - return new DatastoreConfiguration( + public static final ConfigKey DATABASE_VALUES = EnduringKey.wrap(AbstractKey.of(c -> { + int maxPoolSize = c.getInt("data.pool-settings.maximum-pool-size", c.getInt("data.pool-size", 10)); + int minIdle = c.getInt("data.pool-settings.minimum-idle", maxPoolSize); + int maxLifetime = c.getInt("data.pool-settings.maximum-lifetime", 1800000); + int connectionTimeout = c.getInt("data.pool-settings.connection-timeout", 15000); + return new StorageCredentials( c.getString("data.address", null), c.getString("data.database", null), c.getString("data.username", null), c.getString("data.password", null), - c.getInt("data.pool-size", 10) + maxPoolSize, minIdle, maxLifetime, connectionTimeout ); })); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/DatastoreConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java similarity index 90% rename from common/src/main/java/me/lucko/luckperms/common/storage/DatastoreConfiguration.java rename to common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java index 04eebbae..81c2d433 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/DatastoreConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageCredentials.java @@ -30,12 +30,15 @@ import lombok.Getter; @Getter @AllArgsConstructor -public class DatastoreConfiguration { +public class StorageCredentials { private final String address; private final String database; private final String username; private final String password; - private int poolSize; + private int maxPoolSize; + private int minIdleConnections; + private int maxLifetime; + private int connectionTimeout; } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java index f41bae3e..234ee334 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java @@ -53,7 +53,7 @@ import me.lucko.luckperms.common.node.NodeHeldPermission; import me.lucko.luckperms.common.node.NodeModel; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.references.UserIdentifier; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; import me.lucko.luckperms.common.storage.dao.AbstractDao; import org.bson.Document; @@ -74,14 +74,14 @@ import java.util.stream.Collectors; @SuppressWarnings("unchecked") public class MongoDao extends AbstractDao { - private final DatastoreConfiguration configuration; + private final StorageCredentials configuration; private MongoClient mongoClient; private MongoDatabase database; @Getter private final String prefix; - public MongoDao(LuckPermsPlugin plugin, DatastoreConfiguration configuration, String prefix) { + public MongoDao(LuckPermsPlugin plugin, StorageCredentials configuration, String prefix) { super(plugin, "MongoDB"); this.configuration = configuration; this.prefix = prefix; diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/HikariConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/HikariConnectionFactory.java index 7cd7391f..41cae0e3 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/HikariConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/HikariConnectionFactory.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.common.storage.dao.sql.connection.hikari; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; import me.lucko.luckperms.common.storage.dao.sql.connection.AbstractConnectionFactory; import java.sql.Connection; @@ -40,10 +40,10 @@ import java.util.concurrent.TimeUnit; public abstract class HikariConnectionFactory extends AbstractConnectionFactory { - protected final DatastoreConfiguration configuration; + protected final StorageCredentials configuration; private HikariDataSource hikari; - public HikariConnectionFactory(String name, DatastoreConfiguration configuration) { + public HikariConnectionFactory(String name, StorageCredentials configuration) { super(name); this.configuration = configuration; } @@ -62,7 +62,6 @@ public abstract class HikariConnectionFactory extends AbstractConnectionFactory address = addressSplit[0]; String port = addressSplit.length > 1 ? addressSplit[1] : "3306"; - config.setMaximumPoolSize(configuration.getPoolSize()); config.setDataSourceClassName(getDriverClass()); config.addDataSourceProperty("serverName", address); config.addDataSourceProperty("port", port); @@ -79,9 +78,10 @@ public abstract class HikariConnectionFactory extends AbstractConnectionFactory appendConfigurationInfo(config); appendProperties(config); - // We will wait for 15 seconds to get a connection from the pool. - // Default is 30, but it shouldn't be taking that long. - config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000 + config.setMaximumPoolSize(configuration.getMaxPoolSize()); + config.setMinimumIdle(configuration.getMinIdleConnections()); + config.setMaxLifetime(configuration.getMaxLifetime()); + config.setConnectionTimeout(configuration.getConnectionTimeout()); // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked. config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000 diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MariaDbConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MariaDbConnectionFactory.java index 634b3339..609c73fc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MariaDbConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MariaDbConnectionFactory.java @@ -27,10 +27,10 @@ package me.lucko.luckperms.common.storage.dao.sql.connection.hikari; import com.zaxxer.hikari.HikariConfig; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; public class MariaDbConnectionFactory extends HikariConnectionFactory { - public MariaDbConnectionFactory(DatastoreConfiguration configuration) { + public MariaDbConnectionFactory(StorageCredentials configuration) { super("MariaDB", configuration); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MySqlConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MySqlConnectionFactory.java index 087c9e90..8e2f5517 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MySqlConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/MySqlConnectionFactory.java @@ -27,10 +27,10 @@ package me.lucko.luckperms.common.storage.dao.sql.connection.hikari; import com.zaxxer.hikari.HikariConfig; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; public class MySqlConnectionFactory extends HikariConnectionFactory { - public MySqlConnectionFactory(DatastoreConfiguration configuration) { + public MySqlConnectionFactory(StorageCredentials configuration) { super("MySQL", configuration); } @@ -42,7 +42,6 @@ public class MySqlConnectionFactory extends HikariConnectionFactory { String port = addressSplit.length > 1 ? addressSplit[1] : "3306"; String database = configuration.getDatabase(); - config.setMaximumPoolSize(configuration.getPoolSize()); config.setJdbcUrl("jdbc:mysql://" + address + ":" + port + "/" + database); config.setUsername(configuration.getUsername()); config.setPassword(configuration.getPassword()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/PostgreConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/PostgreConnectionFactory.java index 0ee660a4..968cdbd2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/PostgreConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/connection/hikari/PostgreConnectionFactory.java @@ -27,10 +27,10 @@ package me.lucko.luckperms.common.storage.dao.sql.connection.hikari; import com.zaxxer.hikari.HikariConfig; -import me.lucko.luckperms.common.storage.DatastoreConfiguration; +import me.lucko.luckperms.common.storage.StorageCredentials; public class PostgreConnectionFactory extends HikariConnectionFactory { - public PostgreConnectionFactory(DatastoreConfiguration configuration) { + public PostgreConnectionFactory(StorageCredentials configuration) { super("PostgreSQL", configuration); } @@ -45,7 +45,6 @@ public class PostgreConnectionFactory extends HikariConnectionFactory { String username = configuration.getUsername(); String password = configuration.getPassword(); - config.setMaximumPoolSize(configuration.getPoolSize()); config.setDataSourceClassName("org.postgresql.ds.PGSimpleDataSource"); config.addDataSourceProperty("serverName", address); config.addDataSourceProperty("portNumber", port); diff --git a/sponge/src/main/resources/luckperms.conf b/sponge/src/main/resources/luckperms.conf index 4a021371..6efe4afd 100644 --- a/sponge/src/main/resources/luckperms.conf +++ b/sponge/src/main/resources/luckperms.conf @@ -245,7 +245,36 @@ data { database="minecraft" username="root" password="" - pool-size=10 # The size of the MySQL connection pool. + + # These settings apply to the MySQL connection pool. + # The default values will be suitable for the majority of users. + # Do not change these settings unless you know what you're doing! + pool-settings { + + # Sets the maximum size of the MySQL connection pool. + # Basically this value will determine the maximum number of actual + # connections to the database backend. + # + # More information about determining the size of connection pools can be found here: + # https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing + maximum-pool-size=10 + + # Sets the minimum number of idle connections that the pool will try to maintain. + # + # For maximum performance and responsiveness to spike demands, it is recommended to not set + # this value and instead allow the pool to act as a fixed size connection pool. + # (set this value to the same as 'maximum-pool-size') + minimum-idle=10 + + # This setting controls the maximum lifetime of a connection in the pool in milliseconds. + # The value should be at least 30 seconds less than any database or infrastructure imposed + # connection time limit. + maximum-lifetime=1800000 # 30 minutes + + # This setting controls the maximum number of milliseconds that the plugin will wait for a + # connection from the pool, before timing out. + connection-timeout=15000 # 15 seconds + } # The prefix for all LuckPerms tables. Change this is you want to use different tables for # different servers.