简体   繁体   English

如何诊断泄露的http连接(org.apache.http.impl.conn.tsccm.ConnPoolByRoute)

[英]How to diagnose leaked http connections (org.apache.http.impl.conn.tsccm.ConnPoolByRoute)

I have a multithreaded java program that runs on Amazon's EC2. 我有一个在Amazon的EC2上运行的多线程java程序。 It queries and fetches data items from a vendor via HttpPost and HttpGet, using a org.apache.http.impl.client.DefaultHttpClient. 它使用org.apache.http.impl.client.DefaultHttpClient通过HttpPost和HttpGet从供应商查询和获取数据项。 Concurrently, it pushes the retrieved data items into S3 using AWS's Java SDK. 同时,它使用AWS的Java SDK将检索到的数据项推送到S3。

After a few days of running, I get the symptoms that normally come with http connection leaks: 运行几天后,我得到通常伴随http连接泄漏的症状:

org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:417)
at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:300)
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:224)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:391)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)

Since both AWS and my requests to the data vendor use Http connections, I am not quite sure where exactly I forget to HttpEntity.consume() , or S3ObjectInputStream.close() (unless it is yet something else...). 由于AWS和我对数据供应商的请求都使用Http连接,我不太确定我究竟忘记了HttpEntity.consume()S3ObjectInputStream.close() (除非它还有其他东西......)。

So here is my question: are there ways to monitor org.apache.http.impl.conn.tsccm.ConnPoolByRoute so that at least I can detect when I am starting to leak connections/entities not properly consumed/http streams not closed? 所以这是我的问题:有没有办法监控org.apache.http.impl.conn.tsccm.ConnPoolByRoute这样至少我可以检测到什么时候我开始泄漏连接/实体未正确消耗/ http流未关闭? (I have a feeling it happens only under certain conditions, eg when certain exceptions are being thrown, by-passing the logic in my code that consumes HttpEntities, closes streams, etc.) Any idea on how to diagnose what eventually causes all my http connections to fail with that ConnectionPoolTimeoutException would be most welcome. (我感觉它只在某些条件下发生,例如,当抛出某些异常时,绕过我的代码中消耗HttpEntities的逻辑,关闭流等等。)任何关于如何诊断最终导致我的所有http的想法使用ConnectionPoolTimeoutException失败的连接将是最受欢迎的。 I don't feel like waiting 4+ days between attempts to fix the root cause of the problem. 我不想在尝试解决问题的根本原因之间等待4天以上。

If you're using the PoolingClientConnectionManager note there are the methods getTotalStats() and getStats(final HttpRoute route) which will give you a PoolStats object with the data you're looking to monitor. 如果您正在使用PoolingClientConnectionManager注释,则有getTotalStats()getStats(final HttpRoute route) ,它们将为您提供一个PoolStats对象,其中包含您要监视的数据。

Just fetch the ConnectionManager from your httpclient: 只需从httpclient获取ConnectionManager:

PoolingClientConnectionManager poolManager = (PoolingClientConnectionManager) httpClient.getConnectionManager();

If you can access the org.apache.http.impl.conn.tsccm.ConnPoolByRoute then set it's connTTL to a low enough value so that it's WaitingThreadAborter will eventually terminate a connection. 如果你可以访问org.apache.http.impl.conn.tsccm.ConnPoolByRoute然后将它的connTTL设置为足够低的值,那么它的WaitingThreadAborter最终将终止连接。 It will show a nice stacktrace there. 它会在那里显示一个很好的堆栈跟踪。 The other option is to use CGLIB or some other bytecode manipulating framework to create a proxy class wrapping org.apache.http.impl.conn.tsccm.ConnPoolByRoute . 另一种选择是使用CGLIB或其他一些字节码操作框架来创建包装org.apache.http.impl.conn.tsccm.ConnPoolByRoute的代理类。 Depending on your environment it might not be that easy to set it up, but it's a rather valuable tool to debug issues like yours. 根据您的环境,设置可能并不那么容易,但它是调试像您这样的问题的一个非常有价值的工具。 (And yes, if you happen to use spring or just plain Aspects the setup will be supereasy :) ) (是的,如果您碰巧使用弹簧或只是简单的Aspects,设置将是超级的:))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:java.lang.NoClassDefFoundError:org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - Java: java.lang.NoClassDefFoundError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager 警告没有为logger找到appender(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) - WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) java.lang.NoClassDefFoundError:org / apache / http / impl / conn / PoolingClientConnectionManager - java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingClientConnectionManager org.apache.http.client-4.3.6:java.lang.NoClassDefFoundError:org.apache.http.impl.conn.PoolingHttpClientConnectionManager - org.apache.http.client-4.3.6: java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager MACOSX-java.lang.NoSuchMethodError:org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V - MACOSX - java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V java.lang.NoClassDefFoundError: - 不能初始化类org.apache.http.impl.conn.ManagedHttpClientConnectionFactory - java.lang.NoClassDefFoundError :-Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory log4j:WARN找不到记录程序的附加程序(org.apache.http.impl.conn.SingleClientConnManager) - log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.SingleClientConnManager) NoClassDefFoundError:org / apache / http / conn / SchemePortResolver-硒 - NoClassDefFoundError: org/apache/http/conn/SchemePortResolver - Selenium org.apache.http.conn.HttpHostConnectException:拒绝连接到http:// localhost - org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused 如何解决Http请求中的org.apache.http.conn.ConnectTimeoutException到另一台服务器? - How to resolve org.apache.http.conn.ConnectTimeoutException in Http Request to another server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM