All Products
Search
Document Center

Alibaba Cloud SDK:Enable the concurrency feature of an SDK client

Last Updated:Jun 16, 2026

Enable the concurrency feature of Alibaba Cloud Classic SDK for Go to send concurrent requests from an SDK client.

Usage notes:

  • Go natively supports concurrency. We recommend that you control concurrent requests at the application layer.

  • The Classic SDK for Go also provides a method to directly send concurrent requests. The concurrent requests are controlled within the SDK.

package main

import (
        "fmt"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
	"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
	"os"
)

func main() {
	// Optional. The maximum number of concurrent requests. Default value: 5.
	poolSize := 2
	// Optional. The maximum number of requests that can be cached. Default value: 1000.
	maxTaskQueueSize := 5
	// Enable the asynchronous call feature when you create an SDK client.
	config := sdk.NewConfig().WithEnableAsync(true).WithGoRoutinePoolSize(poolSize).WithMaxTaskQueueSize(maxTaskQueueSize)
	// Initialize the credential.
	credential := &credentials.AccessKeyCredential{AccessKeyId: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), AccessKeySecret: os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")}
	ecsClient, err := ecs.NewClientWithOptions("cn-beijing", config, credential)
        if err != nil {
		fmt.Printf("Error : %v\n", err)
		return
	}	
        // You can also enable the asynchronous call feature after you initialize the SDK client.
	ecsClient.EnableAsync(poolSize, maxTaskQueueSize)
}