zoukankan      html  css  js  c++  java
  • Configure HttpClient correctly

    References:

    [1] http://dev.bizo.com/2013/04/sensible-defaults-for-apache-httpclient.html

     We have hit an issue recently that the httpClient is too slow to send messages to the hosts. Finally, we found that we just use 

    CloseableHttpClient httpClient = HttpClients.custom().build();
    

    to create a default httpClient and not even configure it. We shoud have set at least MaxTotal and MaxPerRoute.

    MaxTotal is the maximum total number of connections in the pool. MaxPerRoute is the maximum number of connections to a particular host. If the client attempts to make a request and either of these maximums have been reached, then by default the client will block until a connection is free. Unfortunately the default for MaxTotal is 20 and the default MaxPerRoute is only 2.

    Finally we solved th issue by setting

    CloseableHttpClient httpClient = HttpClients.custom()
            .setMaxConnTotal(threadpoolSize) // threadpoolSize = 100
            .setMaxConnPerRoute(threadpoolSize)
            .build();
    

      

  • 相关阅读:
    mabatis配置文件yml配置打印sql
    java使用validator检验bean
    vue项目 老是报错 气的我就不行
    注入为空
    软件测试基础
    单元测试实战
    软件测试基础
    For循环案例---九九乘法表
    软件测试基础
    软件测试基础
  • 原文地址:https://www.cnblogs.com/codingforum/p/6099173.html
Copyright © 2011-2022 走看看