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();
    

      

  • 相关阅读:
    MySQL(错误1064)
    如何判断是手机还是电脑访问网站
    Oracle表分区
    分离Date数据
    多对多
    一对多
    SQLalchemy基础
    paramiko上传下载
    paramiko
    automap
  • 原文地址:https://www.cnblogs.com/codingforum/p/6099173.html
Copyright © 2011-2022 走看看