From f254b3a3904caf99aa773126656160fc21a1c4fd Mon Sep 17 00:00:00 2001 From: wudi <676366545@qq.com> Date: Mon, 24 Jun 2024 15:34:49 +0800 Subject: [PATCH] add http reuse strategy --- .../org/apache/doris/flink/sink/HttpUtil.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/HttpUtil.java b/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/HttpUtil.java index baf3391ca..6172c6ac3 100644 --- a/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/HttpUtil.java +++ b/flink-doris-connector/src/main/java/org/apache/doris/flink/sink/HttpUtil.java @@ -17,15 +17,25 @@ package org.apache.doris.flink.sink; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.NoConnectionReuseStrategy; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultRedirectStrategy; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; +import java.util.concurrent.TimeUnit; + /** * util to build http client. */ public class HttpUtil { + private RequestConfig requestConfigStream = + RequestConfig.custom() + .setConnectTimeout(60 * 1000) + .setConnectionRequestTimeout(60 * 1000) + .build(); + private final HttpClientBuilder httpClientBuilder = HttpClients .custom() .setRedirectStrategy(new DefaultRedirectStrategy() { @@ -33,7 +43,11 @@ public class HttpUtil { protected boolean isRedirectable(String method) { return true; } - }); + }) + .setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE) + .evictExpiredConnections() + .evictIdleConnections(60, TimeUnit.SECONDS) + .setDefaultRequestConfig(requestConfigStream); public CloseableHttpClient getHttpClient() { return httpClientBuilder.build();