2013-10-09 204 views
0

我的应用程序必须处理客户端http请求,与某些API进行通信并将数据返回给客户端。我宣布全球RestTemplate我的应用程序,如下图所示:HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(int)似乎无法正常工作

<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"> 
    <constructor-arg index="0"> 
     <bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams"> 
      <property name="authenticationPreemptive" value="false" /> 
     </bean> 
    </constructor-arg> 
    <constructor-arg index="1"> 
     <bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"> 
      <property name="params"> 
       <bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams"> 
        <property name="connectionTimeout" value="20000" /> 
        <property name="soTimeout" value="20000" /> 
        <property name="defaultMaxConnectionsPerHost" value="30" /> 
        <property name="maxTotalConnections" value="500" /> 
       </bean> 
      </property> 
     </bean> 
    </constructor-arg> 
</bean> 

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> 
    <property name="requestFactory"> 
     <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory"> 
      <property name="httpClient" ref="httpClient" /> 
     </bean> 
    </property> 
</bean> 

通过设置defaultMaxConnectionsPerHost,我希望每个主机同时连接数为。但是通过我的测试,看起来实际的数字最多是不管我设置了多大defaultMaxConnectionsPerHost

我怎么办我的测试:

  • 客户端:通过浏览器同时发送20请求我的web应用程序(我试过Firefox和Chrome)。
  • 服务器端:

    • 问题1:为什么每个主机同时连接的数量不是30预期netstat

    问题获取连接数?

  • 问题2:我的应用程序必须每秒向一台主机发送约10个请求。每个请求持续2秒。那么我应该设置什么合适的价值defaultMaxConnectionsPerHost

回答

0

经过一些更多的测试后,我发现我在测试中提到的测试方式可能是错误的。并且defaultMaxConnectionsPerHost按预期工作。

相关问题