[
https://issues.apache.org/jira/browse/KNOX-3592?focusedWorklogId=1055713&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055713
]
ASF GitHub Bot logged work on KNOX-3592:
----------------------------------------
Author: ASF GitHub Bot
Created on: 18/Nov/26 14:54
Start Date: 18/Nov/26 14:54
Worklog Time Spent: 10m
Work Description: smolnar82 commented on code in PR #1526:
URL: https://github.com/apache/knox/pull/1526#discussion_r4615925272
##########
gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java:
##########
@@ -361,6 +361,16 @@ public class GatewayConfigImpl extends Configuration
implements GatewayConfig {
private static final String GATEWAY_DATABASE_H2_ENCRYPTION_ENABLED =
GATEWAY_CONFIG_FILE_PREFIX + ".database.h2.encryption.enabled";
private static final String GATEWAY_DATABASE_H2_ENCRYPTION_PASSPHRASE_ALIAS
= GATEWAY_CONFIG_FILE_PREFIX + ".database.h2.encryption.passphrase.alias";
private static final String
DEFAULT_GATEWAY_DATABASE_H2_ENCRYPTION_PASSPHRASE_ALIAS =
"h2_encryption_passphrase";
+ private static final String GATEWAY_DATABASE_POOL_ENABLED =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.enabled";
+ private static final String GATEWAY_DATABASE_POOL_MAX_SIZE =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.max.size";
+ private static final String GATEWAY_DATABASE_POOL_MIN_IDLE =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.min.idle";
+ private static final String GATEWAY_DATABASE_POOL_CONNECTION_TIMEOUT =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.connection.timeout.ms";
+ private static final String GATEWAY_DATABASE_POOL_IDLE_TIMEOUT =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.idle.timeout.ms";
+ private static final String GATEWAY_DATABASE_POOL_MAX_LIFETIME =
GATEWAY_CONFIG_FILE_PREFIX + ".database.pool.max.lifetime.ms";
+ private static final int DEFAULT_GATEWAY_DATABASE_POOL_MAX_SIZE = 10;
+ private static final long DEFAULT_GATEWAY_DATABASE_POOL_CONNECTION_TIMEOUT =
TimeUnit.SECONDS.toMillis(30);
+ private static final long DEFAULT_GATEWAY_DATABASE_POOL_IDLE_TIMEOUT =
TimeUnit.MINUTES.toMillis(10);
+ private static final long DEFAULT_GATEWAY_DATABASE_POOL_MAX_LIFETIME =
TimeUnit.MINUTES.toMillis(30);
Review Comment:
The pool retires the connection, and callers don't notice:
- An idle connection is closed and replaced in the background.
- An in-use connection is never closed under the caller; it's closed when
it's returned.
- Each connection gets a random lifetime of 75–100% of `max.lifetime.ms`
(22.5–30 min with the 30 min default), so connections don't all retire at once.
This closes connections before anything else drops them silently, such as a
firewall or load balancer idle timeout, or a database-side limit. `0` disables
it.
Issue Time Tracking
-------------------
Worklog Id: (was: 1055713)
Time Spent: 50m (was: 40m)
> Use a pooled JDBC DataSource for the gateway database
> -----------------------------------------------------
>
> Key: KNOX-3592
> URL: https://issues.apache.org/jira/browse/KNOX-3592
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxIDF
> Reporter: Sandor Molnar
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> None of the {{DataSourceFactory}} implementations pool connections:
> * Postgres uses {{PGSimpleDataSource}}.
> * MySQL and MariaDB use {{MysqlDataSource}}.
> * Oracle uses plain {{OracleDataSource}}.
> * H2 uses {{JdbcDataSource}}.
> As a result, every {{getConnection()}} opens a new TCP connection and logs in
> again (on Postgres that is SCRAM-SHA-256, plus a TLS handshake if SSL is
> enabled). {{DataSourceProvider}} also builds a separate DataSource for each
> service, e.g. token state, delegation policies, trusted OIDC issuers,
> federated identity and the remote config monitor.
> On hot paths this cost repeats on every request. For example, RFC 8693 token
> exchange does a delegation policy lookup per exchange, and
> {{JDBCTokenStateService}} runs two statements per metadata entry for each new
> token. Thread dumps under load show request threads blocked in connection
> setup and authentication. With remote databases the cost grows with network
> latency.
> *Proposal:*
> * Wrap the vendor DataSource in a connection pool, for example HikariCP
> (Apache-2.0).
> * Share one pooled DataSource across all DB-backed services.
> * Make the pool configurable in {{gateway-site.xml}}:
> {{gateway.database.pool.*}} for max size, min idle, connection timeout, idle
> timeout and max lifetime, with sensible defaults.
> * Close the pool on gateway shutdown.
> * Existing connection, credential-alias and SSL settings keep working
> unchanged.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)