私は1日約20Mリクエストを提供しているRESTサービスを持っています。私は次の例外を取得しています。この問題は断続的なもので、この問題をリクエストの量に関連付けることはできませんでした。ボリュームが非常に低いときにも週末にこの例外が発生します。私はsetStaleConnectionCheckEnabled
をチェックして、偶然の接続がないことを確認します。ログからSocketTimeoutException:読み取りタイムアウトされたHTTPクライアント
、私はそのサービスが300ミリ秒以内に要求の大半を答え見ることができますが、それはに接続するためのクライアントのために時間がかかった - さらに分析した後いくつかの詳細:私はhttpclient 4.3.4
アップデートを使用していますサービス自体と時間応答が受信されると、6秒のしきい値を超え、例外タイムアウトになりました。
getCause(): java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:891)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:220)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
at com.sample.SampleClient.doGet(SampleClient.java:137)
クライアント:
public MyRespBean doGet(String host, String path, List<NameValuePair> nameValuePairs, Map<String, String> headers, AuthParams authParams)
throws URISyntaxException, IOException
{
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(6000).setConnectTimeout(6000).setStaleConnectionCheckEnabled(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
URI uri = buildUri(host, path, nameValuePairs);
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("Connection", "close");
addHeaders(httpGet, headers, authParams);
**//Error occurs at the following line**
MyRespBean respBean = (MyRespBean)httpClient.execute(httpGet, new SimpleResponseHandler());
httpClient.close();
return respBean;
}
はい、私はサービスとクライアントの両方を所有しています。ログから、サービスが300ミリ秒以内に応答したことがわかりましたが、サービス自体に接続するのに時間がかかり、時間応答が受信されると、6秒のしきい値を超えて読み取りタイムアウト例外に遭遇しました。 – Pankaj