This is an automated email from the ASF dual-hosted git repository.
bchapuis pushed a commit to branch mbtiles-perf
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
The following commit(s) were added to refs/heads/mbtiles-perf by this push:
new 8b4f6a99 Increase the size of idle connections and log config
8b4f6a99 is described below
commit 8b4f6a995773153fa020d97dc854d5e5df7258ca
Author: Bertil Chapuis <[email protected]>
AuthorDate: Tue Aug 22 21:10:49 2023 +0200
Increase the size of idle connections and log config
---
.../main/java/org/apache/baremaps/utils/PostgresUtils.java | 13 ++++++++++---
.../java/org/apache/baremaps/workflow/WorkflowContext.java | 2 +-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
b/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
index 5c6bf210..4eda2e5e 100644
--- a/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
+++ b/baremaps-core/src/main/java/org/apache/baremaps/utils/PostgresUtils.java
@@ -23,13 +23,18 @@ import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
+import javax.sql.DataSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/** A helper class for creating data sources and executing queries. */
public final class PostgresUtils {
+ private static final Logger logger =
LoggerFactory.getLogger(PostgresUtils.class);
+
private PostgresUtils() {}
- public static HikariDataSource createDataSource(String host, Integer port,
String database,
+ public static DataSource createDataSource(String host, Integer port, String
database,
String username, String password) {
return createDataSource(
String.format("jdbc:postgresql://%s:%s/%s?&user=%s&password=%s", host,
port,
@@ -43,7 +48,7 @@ public final class PostgresUtils {
* @param url the JDBC url
* @return the data source
*/
- public static HikariDataSource createDataSource(String url) {
+ public static DataSource createDataSource(String url) {
return createDataSource(url, Runtime.getRuntime().availableProcessors() *
2);
}
@@ -54,13 +59,15 @@ public final class PostgresUtils {
* @param poolSize the pool size
* @return the data source
*/
- public static HikariDataSource createDataSource(String url, int poolSize) {
+ public static DataSource createDataSource(String url, int poolSize) {
if (poolSize < 1) {
throw new IllegalArgumentException("PoolSize cannot be inferior to 1");
}
HikariConfig config = new HikariConfig();
config.setJdbcUrl(url);
config.setMaximumPoolSize(poolSize);
+ config.setMinimumIdle(poolSize);
+ logger.info("HikariConfig: {}", config);
return new HikariDataSource(config);
}
diff --git
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
index eff85f26..b03060ca 100644
---
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
+++
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/WorkflowContext.java
@@ -33,7 +33,7 @@ public class WorkflowContext {
* @return the data source
*/
public DataSource getDataSource(String database) {
- return dataSources.computeIfAbsent(database, d ->
PostgresUtils.createDataSource(d));
+ return dataSources.computeIfAbsent(database,
PostgresUtils::createDataSource);
}
}