Adolph
Engineer
Engineer
  • UID623
  • Fans2
  • Follows1
  • Posts72
Reads:1280Replies:0

Alibaba Cloud OSS Java SDK timeout settings

Created#
More Posted time:Oct 14, 2016 11:43 AM
It involves five phases for an Alibaba Cloud OSS Java SDK to send a request:


Phase I
• Obtain a connection from the connection pool. If the maximum connections available are in use, wait for a connection to be released, or throw out ConnectionPoolTimeoutException when the maximum timeout is reached. If the maximum number of connections is set to a high value, but you don't want to occupy too many connections in the connection pool, the SDK will automatically turn off connections that have been idle for too long.
• The maximum number of connections is 1024 by default, and you can use ClientConfiguration.setMaxConnections to adjust settings.
To disable timeout for obtaining connections from the connection pool by default, you can use ClientConfiguration.set ConnectionRequestTimeout to adjust settings. By default, the SDK will shut down connections that have been idle for 60 seconds and you can use ClientConfiguration.setIdleConnectionTime to adjust settings.
• OSS Java SDK uses connection pooling to avoid repeated use of connections and reduce the time needed to connect/disconnect while sending requests, so that the service efficiency can be improved and the server stability can be enhanced.
Phase II
• If the connection obtained from the connection pool hasn't been connected to the OSS, a new connection will be created. The newly created connection has a timeout time, and the ConnectionTimeout error will be prompted at timeout. If the connection obtained from the connection pool has been connected to the OSS, the connection idle time will be checked. If the connection idle time does not exceed the threshold value, the connection is reused; otherwise, the connection validity is checked. If it is valid, it is used; otherwise, a new connection will be created.
• The default timeout for the newly created connection is 50 seconds, and you can use ClientConfiguration.setConnectionTimeout for settings.
• By default, if a connection is idle for two seconds or above, its validity will be checked before it is reused.  The validity check function of idle connections has bugs in versions earlier than 2.1.2, but the bug is fixed in version 2.1.2 and above. The cause and problem details can be found in [FAQs].
Phase III
• Send a request. The request sending speed is dependent on the network speed. The request sending timeout is based on the timeout and retransmission mechanism of the TCP protocol stack. Usually you don't need to set the timeout value and it is not configurable for the time being.
• The timeout and retransmission mechanism of Linux-core TCP protocol stack is generally between 15 to 30 minutes.
Phase IV
• After the request is successfully sent, wait for the response. The waiting has a timeout value. When the timeout value is exceeded, SocketTimeout will be thrown. The timeout value for the waiting is 50 seconds by default. You can use ClientConfiguration. setSocketTimeout to adjust settings.
• Please set this parameter according to network conditions.
Phase V
• Receive data. If the data is large, it will be transmitted in multiple packets. When packet N is received, but packet N+1 is not received after the timeout value has been exceeded, SocketTimeout will also be thrown.
The packet time interval timeout and waiting for data response timeout are controlled by the ClientConfiguration.setSocketTimeout parameter.
• Please set this parameter according to network conditions.
In some application scenarios, you need to control the time of the entire request, that is, the sum of time required for the above five phases. For example, in the live video scenario, uploading requests are time sensitive. OSS Java SDK provides time settings at the request level:
// Enabled as needed. Not enabled by default.
ClientConfiguration.setRequestTimeoutEnabled(true);
// Set request timeout. Unit: milliseconds. The default value is 300
ClientConfiguration.setRequestTimeout();


If the request is not completed within the set duration, the request fails and ClientException will be thrown.
Note
• All the timeout units for OSS Java SDK are milliseconds.
Guest