我们正在尝试开发/调整一个restlet客户端,该服务器每秒最多可以发送10次以上的HTTP请求。
The restlet website提供了消耗资源的示例客户端代码。他们的例子是
ClientResource clientResource = new ClientResource(
"http://localhost:8182/rest/test");
TestResource testResource = clientResource.wrap(TestResource.class);
// Retrieve the JSON value
Customer result = testResource.retrieve();
然而other discussions(以及对该维基的评论)表示此方法存在问题。
似乎不清楚是否应调用release()
和/或exhaust()
来释放资源。我试过了。
ClientResource cs = new ClientResource(rootConnectionString);
final Representation rep = cs.post(s);
if (rep != null) {
final long numBytes = rep.exhaust();
rep.release();
}
我们的客户端应用程序不能依赖垃圾收集器来避免资源耗尽。理想情况下,我们会重复使用相同的连接/套接字来提高性能。
我问的原因是我们的应用程序在性能测试中效果不佳,我们看到间歇性问题。我认为这些是客户端,因为负载测试与服务器的其他工具是可以的。
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:149)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:110)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:260)
at org.apache.http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:115)
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:98)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
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)
at org.restlet.ext.httpclient.internal.HttpMethodCall.sendRequest(HttpMethodCall.java:333)
at org.restlet.engine.adapter.ClientAdapter.commit(ClientAdapter.java:111)
at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:109)
at org.restlet.Client.handle(Client.java:190)
at org.restlet.resource.ClientResource.handle(ClientResource.java:1064)
at org.restlet.resource.ClientResource.handleOutbound(ClientResource.java:1153)
at org.restlet.resource.ClientResource.handle(ClientResource.java:996)
at org.restlet.resource.ClientResource.handle(ClientResource.java:972)
at org.restlet.resource.ClientResource.post(ClientResource.java:1381)
at org.restlet.resource.ClientResource.post(ClientResource.java:1327)
真正有用的是一些可以正确清理的示例代码
问候,
基兰