You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
clientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressionjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)question
Hi @Paultagoras, I have taken some new tests - I tried to re-run both my old tests and the project @f1llon provided - with clickhouse-jdbc version 0.8.6 and using JDBC-v2 classes (for example DataSourceImpl instead of the old ClickHouseDataSource).
On one hand, I don't see anymore the Hikari CP issue I first submitted, so many thanks! But on the other hand, I still have some issues:
running @f1llon 's test project, I still have the old logs "route allocated: 1 of N; total allocated: 1 of N"
using the "default" connection pool and running my own tests of concurrent reading, property ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS is ignored: when I run a netstat command on my PC, the number of connections opened toward ClickHouse can be well above the one I set with the ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS property.
Is it enough to initialize my DataSourceImpl with
baseProperties.setProperty(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), "5");
and then use
datasource.getConnection()
to make this configuration effective or do I need to do anything else?
Recommendation: Close — no-op: works as intended max_open_connections limits the HTTP connections of each JDBC Connection, not of the whole DataSource. To limit the total, limit the number of JDBC connections, for example with the HikariCP maximumPoolSize.
Status on main: Not a bug — one client-v2 Client keeps the limit (peak 2 connections, 8 queries in 4 s); a DataSourceImpl with one getConnection() per thread opens one pool per connection (peak 8, 1 s).
Breaking change: No
Duplicates / related: No others
Analysis: jdbc-v2 builds a new Client for each JDBC Connection (jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:98-105), and each Client applies max_open_connections to its own pool (client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java:284). docs/integration-jdbc.md:156-159 documents these two layers of pooling, and makes the JDBC connection pool the task of the application.
Reproduction: complete program and output
importcom.clickhouse.client.api.Client;
importcom.clickhouse.client.api.ClientConfigProperties;
importcom.clickhouse.client.api.query.GenericRecord;
importcom.clickhouse.jdbc.DataSourceImpl;
importjava.sql.Connection;
importjava.sql.ResultSet;
importjava.sql.Statement;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Properties;
importjava.util.concurrent.Callable;
importjava.util.concurrent.ExecutorService;
importjava.util.concurrent.Executors;
importjava.util.concurrent.Future;
importjava.util.concurrent.atomic.AtomicBoolean;
importjava.util.concurrent.atomic.AtomicLong;
publicclassRepro {
staticfinalStringURL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
staticfinalStringPASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
staticfinalintLIMIT = 2;
staticfinalintTHREADS = 8;
// Open HTTP connections on the server, read with a separate client.staticlonghttpConnections(Clientmonitor) {
List<GenericRecord> rows = monitor.queryAll("SELECT value FROM system.metrics WHERE metric = 'HTTPConnection'");
returnrows.get(0).getLong(1);
}
// Runs THREADS tasks at the same time and prints the peak number of HTTP connections that they open.staticvoidmeasure(Stringname, Clientmonitor, Callable<Object> task) throwsException {
longbaseline = httpConnections(monitor);
AtomicLongpeak = newAtomicLong(baseline);
AtomicBooleandone = newAtomicBoolean(false);
Threadsampler = newThread(() -> {
while (!done.get()) {
peak.accumulateAndGet(httpConnections(monitor), Math::max);
try { Thread.sleep(50); } catch (InterruptedExceptione) { return; }
}
});
sampler.start();
ExecutorServicepool = Executors.newFixedThreadPool(THREADS);
List<Callable<Object>> tasks = newArrayList<>();
for (inti = 0; i < THREADS; i++) tasks.add(task);
longstart = System.nanoTime();
Stringerrors = "";
for (Future<Object> f : pool.invokeAll(tasks)) {
try { f.get(); } catch (Exceptione) { errors = " | error: " + e.getCause(); }
}
longms = (System.nanoTime() - start) / 1_000_000;
done.set(true);
sampler.join();
pool.shutdown();
System.out.println(name + ": max_open_connections=" + LIMIT + ", " + THREADS + " concurrent queries, peak extra HTTP connections="
+ (peak.get() - baseline) + ", elapsed=" + ms + " ms" + errors);
}
publicstaticvoidmain(String[] args) throwsException {
try (Clientmonitor = newClient.Builder().addEndpoint(URL).setUsername("default").setPassword(PASSWORD)
.setMaxConnections(1).build()) {
// client-v2: one Client, shared by all threadstry (Clientclient = newClient.Builder().addEndpoint(URL).setUsername("default").setPassword(PASSWORD)
.setMaxConnections(LIMIT).build()) {
measure("client-v2 one Client", monitor, () -> client.queryAll("SELECT sleep(1)"));
}
Thread.sleep(1000);
// jdbc-v2: one DataSourceImpl, each thread calls getConnection(), as in the issuePropertiesprops = newProperties();
props.setProperty("user", "default");
props.setProperty("password", PASSWORD);
props.setProperty(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey(), String.valueOf(LIMIT));
DataSourceImplds = newDataSourceImpl("jdbc:clickhouse:" + URL.replaceFirst("^https?:", "") + "/default", props);
measure("jdbc-v2 DataSourceImpl.getConnection() per thread", monitor, () -> {
try (Connectionconn = ds.getConnection(); Statements = conn.createStatement();
ResultSetrs = s.executeQuery("SELECT sleep(1)")) {
rs.next();
}
returnnull;
});
}
}
}
Output on main (8480ca001), ClickHouse 26.11.4.11:
client-v2 one Client: max_open_connections=2, 8 concurrent queries, peak extra HTTP connections=2, elapsed=4020 ms
jdbc-v2 DataSourceImpl.getConnection() per thread: max_open_connections=2, 8 concurrent queries, peak extra HTTP connections=8, elapsed=1036 ms
Automated triage by Polyglot AI. A maintainer makes the final decision.
clientModule: the client (client-v2; with legacy: the v1 client)connectivityArea: connection, TLS, pool, timeouts, cancellation, transport, compressionjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)question
Activity
polyglotAI-bot commentedon Nov 28, 2026
Recommendation: Close — no-op: works as intended
max_open_connectionslimits the HTTP connections of each JDBCConnection, not of the wholeDataSource. To limit the total, limit the number of JDBC connections, for example with the HikariCPmaximumPoolSize.main: Not a bug — one client-v2Clientkeeps the limit (peak 2 connections, 8 queries in 4 s); aDataSourceImplwith onegetConnection()per thread opens one pool per connection (peak 8, 1 s).Analysis: jdbc-v2 builds a new
Clientfor each JDBCConnection(jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java:98-105), and eachClientappliesmax_open_connectionsto its own pool (client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java:284).docs/integration-jdbc.md:156-159documents these two layers of pooling, and makes the JDBC connection pool the task of the application.Reproduction: complete program and output
Output on
main(8480ca001), ClickHouse 26.11.4.11:Automated triage by Polyglot AI. A maintainer makes the final decision.