mardi 1 avril 2014

Apache HttpClient PoolingHttpClientConnectionManager leaking connections?


Vote count:

0




I am using the Apache Http Client in a Scala application.


The application is fairly high throughput with high parallelism.


I am not sure but I think perhaps I am leaking connections. It seems that whenever the section of code that uses the client gets busy, the application become unresponsive. My suspicion is that I am leaking sockets or something which is then causing other aspects of the application to stop working. It may also not be leaking connections so much as not closing them fast enough.


For more context, occasionally, certain actions lead to this code being executed hundreds of times a minute in parallel. When this happens the Rest API (Spray) of the application becomes unresponsive. There are other areas of the application that operate in high parallelism as well and those never cause a problem with the applications responsiveness.


Cutting back on the parallelism of this section of code does seem to alleviate the problem but isn't a viable long term solution.


Am I forgetting to configure something, or configuring something incorrectly?


The code I am using is something like this:



class SomeClass {
val connectionManager = new PoolingHttpClientConnectionManager()
connectionManager.setDefaultMaxPerRoute(50)
connectionManager.setMaxTotal(500)
val httpClient = HttpClients.custom().setConnectionManager(connectionManager).build()

def postData() {
val post = new HttpPost("http://SomeUrl") // Typically this URL is fixed. It doesn't vary much if at all.
post.setEntity(new StringEntity("Some Data"))
try {
val response = httpClient.execute(post)
try {
// Check the response
} finally {
response.close()
}
} finally {
post.releaseConnection()
}
}
}


asked 28 secs ago






Aucun commentaire:

Enregistrer un commentaire