java - How to to limit connections for the same host (setMaxPerRoute) using PoolingHttpClientConnectionManager? -
i use poolinghttpclientconnectionmanager sending multiple get/post requests in parallel following services:
(1) http://localhost:8080/submit
(2) http://localhost:8080/query
both services heavily used first service (1) has higher priority.
i need set setmaxperroute service (1) consume 80% of available connections. rest 20% limit allocated rest requests longer timeouts (including service (2)). here code:
... poolinghttpclientconnectionmanager httpclientmanager = new poolinghttpclientconnectionmanager(); httpclientmanager.setmaxtotal(10); httpclientmanager.setdefaultmaxperroute(2); httphost httphost = new httphost("http://localhost/submit",8080); httproute submitroute = new httproute(httphost); httpclientmanager.setmaxperroute(submitroute, 8); ...
the problem httphost apparently cannot same differentiate among routes. in fact, 2 url-s have same host (http://localhost:8080), different request pages. in result, both services used same resources.
is there way implement such limitation same host?
thanks help.
after suggestions co-workers i've found solution.
we need control maximum number of connections when requesting url (1) have pool max 20 connections, whereas rest type of requests including request (2) have pool max 2 connections.
it can solved creating 2 different httpclient objects each 1 has own poolinghttpclientconnectionmanager. first manager set setmaxtotal=20, while second setmaxtotal=2.
now each pool has different limitations same domain.
Comments
Post a Comment