Skip to content

Commit

Permalink
Change default http client to apache http client (#1439)
Browse files Browse the repository at this point in the history
* change default http client

* change DEFAULT_BUFFER_SIZE to 8192

---------

Co-authored-by: mzitnik <mark.zitnik@clickhouse.com>
  • Loading branch information
mzitnik and mzitnik authored Sep 12, 2023
1 parent f2ea0e1 commit b670c4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Adding new proxy support [#1338](https://github.com/ClickHouse/clickhouse-java/issues/1338)
* Add support for customer socket factory [#1391](https://github.com/ClickHouse/clickhouse-java/issues/1391)
* use VarHandle in JDK 9+ to read/write numbers
* Change default HTTP Client to Apache HTTP client [#1421](https://github.com/ClickHouse/clickhouse-java/issues/1421)

### Bug Fixes
* Java client threw confusing error when query is invalid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public boolean isWidenUnsignedTypes() {

static final ClickHouseBufferingMode DEFAULT_BUFFERING_MODE = ClickHouseBufferingMode.RESOURCE_EFFICIENT;

static final int DEFAULT_BUFFER_SIZE = 4096;
static final int DEFAULT_BUFFER_SIZE = 8192;
static final int DEFAULT_READ_BUFFER_SIZE = DEFAULT_BUFFER_SIZE;
static final int DEFAULT_WRITE_BUFFER_SIZE = DEFAULT_BUFFER_SIZE;
static final int DEFAULT_MAX_BUFFER_SIZE = 128 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.StandardSocketOptions;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -380,6 +381,22 @@ public HttpConnectionManager(Registry<ConnectionSocketFactory> socketFactory, Cl
if (config.getProxyType() == ClickHouseProxyType.SOCKS) {
builder.setSocksProxyAddress(new InetSocketAddress(config.getProxyHost(), config.getProxyPort()));
}
if (config.hasOption(ClickHouseClientOption.SOCKET_RCVBUF)) {
int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_RCVBUF);
builder.setRcvBufSize(bufferSize > 0 ? bufferSize : config.getReadBufferSize());
} else {
int bufferSize = config.getBufferSize();
int maxQueuedBuffers = config.getMaxQueuedBuffers();
builder.setRcvBufSize(bufferSize * maxQueuedBuffers);
}
if (config.hasOption(ClickHouseClientOption.SOCKET_SNDBUF)) {
int bufferSize = config.getIntOption(ClickHouseClientOption.SOCKET_SNDBUF);
builder.setSndBufSize(bufferSize > 0 ? bufferSize : config.getWriteBufferSize());
} else {
int bufferSize = config.getBufferSize();
int maxQueuedBuffers = config.getMaxQueuedBuffers();
builder.setSndBufSize(bufferSize * maxQueuedBuffers);
}
setDefaultSocketConfig(builder.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public enum ClickHouseHttpOption implements ClickHouseOption {
/**
* HTTP connection provider.
*/
CONNECTION_PROVIDER("http_connection_provider", HttpConnectionProvider.HTTP_URL_CONNECTION,
"HTTP connection provider. HTTP_CLIENT is only supported in JDK 11 or above."),
CONNECTION_PROVIDER("http_connection_provider", HttpConnectionProvider.APACHE_HTTP_CLIENT,
"APACHE HTTP CLIENT connection provider. HTTP_CLIENT is only supported in JDK 11 or above."),
/**
* Custom HTTP headers.
*/
Expand Down

0 comments on commit b670c4c

Please sign in to comment.