A timeout error may occur when you use a client to access Tablestore due to reasons such as network disconnection, network jitter, high server workload, or full garbage collections (GCs) on the client. In this case, you must resolve the issue based on the specific reason.
Problem description
When I use Tablestore SDK for Java to access Tablestore, the "Unexpected error: java.net.SocketTimeoutException" error occurs. Sample error:
content: 11:56:48.072 WARN com.alicloud.openservices.tablestore.core.utils.LogUtil - TraceId:4bc30ca1-f112-2d52-d8b1-61a95072eda5 Failed RetriedCount:1 com.alicloud.openservices.tablestore.ClientException: Unexpected error: java.net.SocketTimeoutExceptionPossible causes
The period of time from when the request is sent to when the response is returned exceeds the upper limit. The upper limit is specified by the socketTimeoutInMillisecond parameter. The default value of the parameter is 30000. The unit is in milliseconds.
In most cases, we recommend that you do not specify a value for the socketTimeoutInMillisecond parameter that is too small. You can specify a value for the socketTimeoutInMillisecond parameter in ClientConfiguration.
Possible causes:
Full GCs are performed on the client.
A network issue, such as different networks or network jitter, occurred.
The latency on the server is higher than the value of the socketTimeoutInMillisecond parameter.
Solution
Check whether full GCs are performed on the client.
Use tools such as jmap or jcmd to troubleshoot the Java virtual machine (JVM). For example, check the memory usage of the JVM, and check whether out of memory (OOM) occurs.
If an OOM error occurs, the I/O thread in the HttpClient background exits. Resolve the issue by using the following methods:
Optimize the code if the memory is improperly used or memory leak occurs.
Increase the memory if the memory is properly used but the JVM resources are insufficient.
If the JVM is idle and a small amount of memory is used, increase the heap memory of the JVM to reduce the probability of errors.
The "SocketTimeoutException" error occurs when the server workload, network error rate, or CPU usage is high. In the preceding scenarios, requests time out before the requests are sent.
Check the network connectivity between the client and the server.
If the "SocketTimeoutException" error occurs for all requests, the network may be disconnected. You can run the ping or curl command to test the network connectivity.
The following sample code provides an example on how to test the network connectivity. In the example, the instance named myinstance is used.
ping myinstance.cn-hangzhou.ots.aliyuncs.com curl myinstance.cn-hangzhou.ots.aliyuncs.comIf a network failure occurs, you may use an internal endpoint in a non-Elastic Compute Service (ECS) environment. Use an appropriate endpoint. For more information, see Endpoints.
If you use a client to access Tablestore from an ECS environment, we recommend that you access Tablestore over a virtual private cloud (VPC) or the classic network.
If the network is connected, the overall latency may be high due to network jitter. Check whether the traffic, bandwidth usage, or packet retransmission rate is high. If the network jitter is high, contact the network engineers to troubleshoot the issue.
Perform the following steps to check whether the latency on the server is high:
Log on to the Tablestore console .
In the top navigation bar, select a resource group and a region.
In the instance list of the Overview page, click the name of the instance.
In the Tables section of the Instance Details tab, click the name of the data table.
On the Monitoring Indicators tab of the Manage Table page, select the table or index, specify a time range, and set Metric Group to Average Latency to view the average latency of different operation types.
If the latency on the server is greater than the value of the socketTimeoutInMillisecond parameter, submit a ticket to contact Tablestore technical support.
