Skip to content

Commit ba490d5

Browse files
committed
added as common property
1 parent 7a8769d commit ba490d5

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

.github/workflows/analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ jobs:
9595
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
9696
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
9797
run: |
98-
mvn --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION \
98+
mvn --batch-mode -DclickhouseVersion=$PREFERRED_LTS_VERSION -Dclient.tests.useNewImplementation=true \
9999
-Panalysis verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
100100
continue-on-error: true

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,22 @@ public Builder setMaxRetries(int maxRetries) {
756756
return this;
757757
}
758758

759+
/**
760+
* Configures client to reuse allocated byte buffers for numbers. It affects how binary format reader is working.
761+
* If set to 'true' then {@link Client#newBinaryFormatReader(QueryResponse)} will construct reader that will
762+
* reuse buffers for numbers. It improves performance for large datasets by reducing number of allocations
763+
* (therefore GC pressure).
764+
* Enabling this feature is safe because each reader suppose to be used by a single thread and readers are not reused.
765+
*
766+
* Default is false.
767+
* @param reuse - if to reuse buffers
768+
* @return
769+
*/
770+
public Builder allowBinaryReaderToReuseBuffers(boolean reuse) {
771+
this.configuration.put("client_allow_binary_reader_to_reuse_buffers", String.valueOf(reuse));
772+
return this;
773+
}
774+
759775
public Client build() {
760776
setDefaults();
761777

@@ -869,6 +885,10 @@ private void setDefaults() {
869885
if (!configuration.containsKey(ClickHouseClientOption.RETRY.getKey())) {
870886
setMaxRetries(3);
871887
}
888+
889+
if (!configuration.containsKey("client_allow_binary_reader_to_reuse_buffers")) {
890+
allowBinaryReaderToReuseBuffers(false);
891+
}
872892
}
873893
}
874894

@@ -1576,8 +1596,7 @@ public CompletableFuture<CommandResponse> execute(String sql) {
15761596
public ClickHouseBinaryFormatReader newBinaryFormatReader(QueryResponse response, TableSchema schema) {
15771597
ClickHouseBinaryFormatReader reader = null;
15781598
// Using caching buffer allocator is risky so this parameter is not exposed to the user
1579-
boolean useCachingBufferAllocator = Boolean.parseBoolean(
1580-
configuration.getOrDefault("client_use_caching_buffer_allocator", "false"));
1599+
boolean useCachingBufferAllocator = MapUtils.getFlag(configuration, "client_allow_binary_reader_to_reuse_buffers");
15811600
BinaryStreamReader.ByteBufferAllocator byteBufferPool = useCachingBufferAllocator ?
15821601
new BinaryStreamReader.CachingByteBufferAllocator() :
15831602
new BinaryStreamReader.DefaultByteBufferAllocator();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.clickhouse.client.query;
2+
3+
public class BinaryReadyReusesBuffersTests extends QueryTests {
4+
5+
public BinaryReadyReusesBuffersTests() {
6+
super(false, false, true);
7+
}
8+
}

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ protected Client.Builder newClient() {
14621462
.compressClientRequest(false)
14631463
.compressServerResponse(true)
14641464
.useHttpCompression(useHttpCompression)
1465-
.setOption("client_use_caching_buffer_allocator", Boolean.valueOf(usePreallocatedBuffers).toString())
1465+
.allowBinaryReaderToReuseBuffers(usePreallocatedBuffers)
14661466
.useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"));
14671467
}
14681468
}

client-v2/src/test/java/com/clickhouse/client/query/UsingPreallocatefReadBuffers.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)