All Products
Search
Document Center

Alibaba Cloud SDK:Configure timeout periods

Last Updated:Jun 25, 2024

This topic describes how to configure timeout periods in the Classic SDK.

Important

Each API operation has a unique request object. The request object is named in the ${API operation name}${Request} format. For example, a request object can be DescribeInstancesRequest.

Timeout periods

  • Connect Time: the time period during which a TCP connection between an SDK client and the server is established. You can configure a timeout period for connection requests.

  • Read Time: the time period after a connection is established. During the time period, a request is sent and a response is returned. You can configure a timeout period for read requests.

The priority levels of the timeout periods that can be configured in the Classic SDK are listed in descending order: the timeout periods that you configure for the current request, the timeout periods that you configure when you initialize the SDK client, and the default timeout periods. The default timeout period for connection requests is 5 seconds, and the default timeout period for read requests is 10 seconds.

IClientProfile profile = DefaultProfile.GetProfile(
    // The region ID.
    "<your-region-id>",
    // Obtain the AccessKey ID of a Resource Access Management (RAM) user from environment variables.
    Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    // Obtain the AccessKey secret of the RAM user from environment variables.
    Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
DefaultAcsClient client = new DefaultAcsClient(profile);

// The timeout periods that you configure when you initialize the SDK client are used for all requests.
DefaultAcsClient client = new DefaultAcsClient();
client.SetConnectTimeoutInMilliSeconds(1024);
client.SetReadTimeoutInMilliSeconds(2048);

// The timeout periods that you configure for the current request are used only for the current request. The following sample code provides an example on how to configure timeout periods for the DescribeInstancesRequest object of Elastic Compute Service (ECS):
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.SetConnectTimeoutInMilliSeconds(1024);
request.SetReadTimeoutInMilliSeconds(2048);