首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >负载测试BindException

负载测试BindException
EN

Stack Overflow用户
提问于 2018-02-15 05:22:48
回答 1查看 775关注 0票数 0

我们有两个应用程序,一个是服务器,另一个是客户端。

服务器在weblogic (应用程序A)上,客户端在春季启动(在tomcat上)。当我们进行A发送请求给B的负载测试时,在某一时刻有上百个绑定异常错误,比负载测试保持正常运行,比绑定异常,比正常运行等等。如果我们使用较高的TPS进行负载测试,则会更频繁地得到这些异常。这是一种情况:

  • 负载测试继续运行,无错误,300 TPS,消息计数10.000
  • 负载测试继续运行,无错误,300 TPS,消息计数30.000
  • 绑定异常,300 TPS,mesasge计数32.000
  • 负载测试继续运行,无错误,300 TPS,消息计数40.000
  • 负载测试继续运行,无错误,300 TPS,消息计数50.000
  • 绑定异常,300 TPS,mesasge计数52.000
  • 负载测试继续运行,没有错误,300 TPS,消息计数60.000 .

错误是:

代码语言:javascript
运行
复制
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://XXXXXXX:9090/api/8252": Cannot assign requested address; nested exception is java.net.BindException: Cannot assign requested address
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666)
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
        at org.springframework.web.client.RestTemplate.postForLocation(RestTemplate.java:355)
        at com.ttech.tims.tes.pushws.impl.PushConsumerThread.tryToSendPushRequest(PushConsumerThread.java:207)
        at com.ttech.tims.tes.pushws.impl.PushConsumerThread.pushMessage(PushConsumerThread.java:162)
        at com.ttech.tims.tes.pushws.impl.PushConsumerThread.run(PushConsumerThread.java:350)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.BindException: Cannot assign requested address
        at sun.nio.ch.Net.connect0(Native Method)
        at sun.nio.ch.Net.connect(Net.java:454)
       at sun.nio.ch.Net.connect(Net.java:446)
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
        at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:432)
        at weblogic.socket.NIOSocketMuxer.newSocket(NIOSocketMuxer.java:364)
        at weblogic.socket.ChannelSocketFactory.createSocket(ChannelSocketFactory.java:98)
        at weblogic.net.http.HttpClient.openServer(HttpClient.java:384)
        at weblogic.net.http.HttpClient.openServer(HttpClient.java:511)
        at weblogic.net.http.HttpClient.New(HttpClient.java:313)
        at weblogic.net.http.HttpClient.New(HttpClient.java:292)
        at weblogic.net.http.HttpURLConnection.connect(HttpURLConnection.java:295)
        at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:652)
        ... 6 more

到目前为止,我已经尝试过:

  • 增加客户端的最大线程数(在application.properties中从100到500等)
  • 将weblogics最大并发线程数从100增加到200 (300,400等)通过控制台
  • 检查服务器和客户端的最大打开文件。
  • 检查服务器和客户端之间的防火墙。
  • 使用Java任务控件进行监视,并检查线程阻塞状态。当出现异常时,由于出现300 are的log4j写入错误,线程将被阻塞。但这并不能解决我们为什么会有这些例外的问题。从Info到Error的日志级别。

到目前为止,还没有得到任何改进,直到一定程度上还得到了BindExceptions的支持。有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-19 10:19:49

感谢EJP的建议。下面是我解决这个问题的方法。Spring模板正在等待unix关闭连接。因此,在达到最大套接字连接后,连接将处于TIME_WAIT状态。当我们将Apache ClientHttpRequestFactory作为spring RestTemplate的工厂发送时,Apache会使用它的连接池来处理请求。以下是实现:

代码语言:javascript
运行
复制
    @Bean("apacheRequestFactory")
    public ClientHttpRequestFactory createRequestFactory() {

        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

        // maximum connections in the pool
        connectionManager.setMaxTotal(this.systemPropertyBean.getPushConsumerThreadCnt());

        // maximum concurrent connection to the hosts is equal to the our push thread count.
        connectionManager.setDefaultMaxPerRoute(this.systemPropertyBean.getPushConsumerThreadCnt());

        RequestConfig config = RequestConfig.custom()
                .setConnectTimeout(this.systemPropertyBean.getPushTimeoutMillis())// 3 sn
                .setConnectionRequestTimeout(this.systemPropertyBean.getPushTimeoutMillis())
                .setSocketTimeout(this.systemPropertyBean.getPushTimeoutMillis()).build(); // read timeout

/*      the Connection Timeout (http.connection.timeout) – the time to establish the connection with the remote host
        the Socket Timeout (http.socket.timeout) – the time waiting for data – after the connection was established; maximum time of inactivity between two data packets
        the Connection Manager Timeout (http.connection-manager.timeout) – the time to wait for a connection from the connection manager/pool
*/        
        CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setDefaultRequestConfig(config).build();
        return new HttpComponentsClientHttpRequestFactory(httpClient);
    }

    @Bean
    public RestTemplate restTemplate() {
// I was using SimpleClientHttpRequestFactory before.
        RestTemplate restTemplate = new RestTemplate(createRequestFactory());
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
        return restTemplate;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48800412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档