lethinker commented on PR #694:
URL:
https://github.com/apache/httpcomponents-client/pull/694#issuecomment-3164276512
> @ok2c @rschmitt can you help me with the problem when I use the
httpAsyncClient( httpclient 5.4.3 、jdk 21) First, I set a 100-second sleep on
the server side to ensure that no response is returned within 100 seconds.
Second I use the `RequestConfig.setResponseTimeout(Timeout.ofMilliseconds(50))`
to set the response timeout value on the client side.
>
> I have modified the timeout multiple times and obtained the following
results. `[async]failed is 1 MILLISECONDS, time usage is 1033`(1 MILLISECONDS
means I set the ResponseTimeout as 1ms, time usage means that client side
timeout after 1033ms) `[async]failed is 10 MILLISECONDS, time usage is 1010`
`[async]failed is 500 MILLISECONDS, time usage is 1015`
>
> `[async]failed is 1000 MILLISECONDS, time usage is 1013` This is the
expected value. `[async]failed is 1020 MILLISECONDS, time usage is 2019` ......
>
> **It seems that the effected ResponseTimeout is being rounded up to the
nearest second, and milliseconds are not taking effect.**
>
> In addition, I used a synchronous httpclient, which works well. I set the
ResponseTimeout = 50ms. `[sync]failed is Read timed out, time usage is 63`
my code is
`
@Service
@EnableScheduling
public class TestService implements InitializingBean {
private CloseableHttpAsyncClient httpAsyncClient;
private HttpClient httpClient;
// SET the ResponseTimeout
private RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(Timeout.ofMilliseconds(500))
.setResponseTimeout(50, TimeUnit.MILLISECONDS)
.build();
@Scheduled(initialDelay = 0L, fixedRateString = "5000")
public void executeTask()
throws NoSuchFieldException, IllegalAccessException,
ExecutionException, InterruptedException {
testSyncDefaultTime();
testAsyncDefaultTime();
}
private void testAsyncDefaultTime()
throws NoSuchFieldException, IllegalAccessException,
ExecutionException, InterruptedException {
// create post request
SimpleHttpRequest request = new SimpleHttpRequest("POST",
"http://127.0.0.1:8888/timeout90s");
long start = System.currentTimeMillis();
Future<SimpleHttpResponse> responseFuture =
httpAsyncClient.execute(request, new FutureCallback<>() {
@Override
public void completed(SimpleHttpResponse simpleHttpResponse) {
System.out.println(
"[async]response is " + simpleHttpResponse + ", time
usage is " + (System.currentTimeMillis() - start));
}
@Override
public void failed(Exception e) {
System.out.println(
"[async]failed is " + e.getMessage() + ", time usage is
" + (System.currentTimeMillis() - start));
}
@Override
public void cancelled() {
System.out.println("[async]request is cancelled, time usage
is " + (System.currentTimeMillis() - start));
}
});
responseFuture.get();
}
private void testSyncDefaultTime() {
BasicClassicHttpRequest httpRequest = new
BasicClassicHttpRequest("POST",
"http://127.0.0.1:8888/huaweidns/timeout90s");
long start = System.currentTimeMillis();
HttpResponse response;
try {
response = httpClient.execute(httpRequest);
} catch (Exception e) {
System.out.println(
"[sync]failed is " + e.getMessage() + ", time usage is " +
(System.currentTimeMillis() - start));
return;
}
System.out.println("[sync]response is " + response + ", time usage
is " + (System.currentTimeMillis() - start));
}
@Override
public void afterPropertiesSet() {
IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
.setSoTimeout(50, TimeUnit.MILLISECONDS) // 设置I/O反应器的超时时间为50毫秒
.setIoThreadCount(8)
.build();
httpAsyncClient = HttpAsyncClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setIOReactorConfig(ioReactorConfig)
.build();
httpAsyncClient.start();
httpClient =
HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
}
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]