Expose more connection pool settings in the config file
This commit is contained in:
parent
df37491199
commit
987ea51264
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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<DatastoreConfiguration> DATABASE_VALUES = EnduringKey.wrap(AbstractKey.of(c -> {
|
||||
return new DatastoreConfiguration(
|
||||
public static final ConfigKey<StorageCredentials> 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
|
||||
);
|
||||
}));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user