并发超时异常AsyncHttpClient

问题描述 投票:0回答:1

在我的项目中,我们使用httpasyncclient调用静态服务。当负载很高时,不断收到以下异常,我们的服务器已挂起。重新启动应用程序后,只有其正常工作。下面是我们的http异步客户端调用的代码。

DefaultAsyncHttpClientConfig config = 
                new DefaultAsyncHttpClientConfig.Builder()
                        .setMaxConnectionsPerHost(500)
                        .setMaxConnections(500)
                        .setPooledConnectionIdleTimeout(100).setConnectionTtl(500)
                        .setConnectTimeout(30000)
                        .setReadTimeout(30000).build();
         AsyncHttpClient asyncClient = asyncHttpClient(config); 

         Response response = asyncClient.preparePost(url).setBody(json)
                .addHeader("Content-Type", ContentType.APPLICATION_JSON)
                .execute().get();
            if (response != null) {
                String responseMsg = response.getResponseBody();
                System.err.println("responseMsg :: " + responseMsg);
            }

java.util.concurrent.TimeoutException: Read timeout to webapp/xxx.xxx.xxx.xxxx:xx after 30000 ms
    at org.asynchttpclient.netty.timeout.TimeoutTimerTask.expire(TimeoutTimerTask.java:43)
    at org.asynchttpclient.netty.timeout.ReadTimeoutTimerTask.run(ReadTimeoutTimerTask.java:56)
    at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:670)
    at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:745)
    at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:473)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    ... 1 common frames omitted
Wrapped by: java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: Read timeout to webapp/xxx.xxx.xxx.xxxx:xx after 30000 ms
    at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
    at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
    at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:202)

为什么asynchttpclient无法处理更多负载。如何解决此问题?任何帮助将不胜感激!!

java rest asynchttpclient
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.