Menyediakan throughput skala otomatis pada database atau kontainer di Azure Cosmos DB - API untuk NoSQL

BERLAKU UNTUK: NoSQL

Artikel ini menjelaskan cara menyediakan throughput skala otomatis pada database atau kontainer (koleksi, grafik, atau tabel) di Azure Cosmos DB untuk NoSQL. Anda dapat mengaktifkan skala otomatis pada satu kontainer, atau provisikan throughput skala otomatis pada database dan membagikannya di antara semua kontainer dalam database.

Jika Anda menggunakan API yang berbeda, lihat artikel API untuk MongoDB, API untuk Cassandra, API untuk Gremlin untuk menyediakan throughput.

Portal Azure

Buat database atau kontainer baru dengan skala otomatis

  1. Masuk ke portal Microsoft Azure atau Microsoft Azure Cosmos DB Explorer.

  2. Buka akun Azure Cosmos DB Anda dan buka tab Data Explorer.

  3. Pilih Kontainer Baru. Masukkan nama untuk database, kontainer, dan kunci partisi Anda. Di bawah throughput database atau kontainer, pilih opsi Autoscale, dan atur throughput maksimum (RU/dtk) yang Anda inginkan untuk diskalakan oleh database atau kontainer.

    Buat kontainer dan kpnfigurasikan throughput otomatis yang tersedia

  4. PilihOK.

Untuk menyediakan skala otomatis pada database throughput bersama, pilih opsi Provisikan throughput database saat membuat database baru.

Aktifkan skala otomatis pada database atau kontainer yang ada

  1. Masuk ke portal Microsoft Azure atau Microsoft Azure Cosmos DB Explorer.

  2. Buka akun Azure Cosmos DB Anda dan buka tab Data Explorer.

  3. Pilih Skala dan Pengaturan untuk kontainer Anda, atau Skala untuk database Anda.

  4. Di bawah Skala, pilih opsi Skala otomatis dan Simpan.

    Mengaktifkan skala otomatis pada kontainer yang sudah ada

Catatan

Saat Anda mengaktifkan skala otomatis pada database atau kontainer yang ada, nilai awal untuk MAX RU/s ditentukan oleh sistem, berdasarkan pengaturan throughput dan penyimpanan yang tersedia manual saat ini. Setelah operasi selesai, Anda dapat mengubah RU/s maksimal jika diperlukan. Pelajari lebih lanjut.

Microsoft Azure Cosmos DB .NET V3 SDK

Gunakan versi 3.9 atau yang lebih tinggi dari Azure Cosmos DB .NET SDK untuk API untuk NoSQL untuk mengelola sumber daya skala otomatis.

Penting

Anda dapat menggunakan .NET SDK untuk membuat sumber daya skala otomatis baru. SDK tidak mendukung migrasi antara throughput skala otomatis dan standar (manual). Skenario migrasi saat ini hanya didukung di portal Microsoft Azure, CLI, dan PowerShell.

Buat database dengan throughput bersama

// Create instance of CosmosClient
CosmosClient cosmosClient = new CosmosClient(Endpoint, PrimaryKey);
 
// Autoscale throughput settings
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000); //Set autoscale max RU/s

//Create the database with autoscale enabled
database = await cosmosClient.CreateDatabaseAsync(DatabaseName, throughputProperties: autoscaleThroughputProperties);

Buat kontainer dengan throughput khusus

// Get reference to database that container will be created in
Database database = await cosmosClient.GetDatabase("DatabaseName");

// Container and autoscale throughput settings
ContainerProperties autoscaleContainerProperties = new ContainerProperties("ContainerName", "/partitionKey");
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(1000); //Set autoscale max RU/s

// Create the container with autoscale enabled
container = await database.CreateContainerAsync(autoscaleContainerProperties, autoscaleThroughputProperties);

Baca throughput saat ini (RU/s)

// Get a reference to the resource
Container container = cosmosClient.GetDatabase("DatabaseName").GetContainer("ContainerName");

// Read the throughput on a resource
ThroughputProperties autoscaleContainerThroughput = await container.ReadThroughputAsync(requestOptions: null); 

// The autoscale max throughput (RU/s) of the resource
int? autoscaleMaxThroughput = autoscaleContainerThroughput.AutoscaleMaxThroughput;

// The throughput (RU/s) the resource is currently scaled to
int? currentThroughput = autoscaleContainerThroughput.Throughput;

Ubah throughput maksimal skala otomatis (RU/s)

// Change the autoscale max throughput (RU/s)
await container.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(newAutoscaleMaxThroughput));

Microsoft Azure Cosmos DB Java V4 SDK

Anda dapat menggunakan Versi 4.0 atau yang lebih tinggi dari Azure Cosmos DB Java SDK untuk API untuk NoSQL untuk mengelola sumber daya skala otomatis.

Penting

Anda dapat menggunakan Java SDK untuk membuat sumber daya skala otomatis baru. SDK tidak mendukung migrasi antara throughput skala otomatis dan standar (manual). Skenario migrasi saat ini hanya didukung di portal Microsoft Azure, CLI, dan PowerShell.

Buat database dengan throughput bersama

// Create instance of CosmosClient
CosmosAsyncClient client = new CosmosClientBuilder()
    .setEndpoint(HOST)
    .setKey(PRIMARYKEY)
    .setConnectionPolicy(CONNECTIONPOLICY)
    .buildAsyncClient();

// Autoscale throughput settings
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(1000); //Set autoscale max RU/s

//Create the database with autoscale enabled
CosmosAsyncDatabase database = client.createDatabase(databaseName, autoscaleThroughputProperties).block().getDatabase();

Buat kontainer dengan throughput khusus

// Get reference to database that container will be created in
CosmosAsyncDatabase database = client.createDatabase("DatabaseName").block().getDatabase();

// Container and autoscale throughput settings
CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties("ContainerName", "/partitionKey");
ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.createAutoscaledThroughput(1000); //Set autoscale max RU/s

// Create the container with autoscale enabled
CosmosAsyncContainer container = database.createContainer(autoscaleContainerProperties, autoscaleThroughputProperties, new CosmosContainerRequestOptions())
                                .block()
                                .getContainer();

Baca throughput saat ini (RU/s)

// Get a reference to the resource
CosmosAsyncContainer container = client.getDatabase("DatabaseName").getContainer("ContainerName");

// Read the throughput on a resource
ThroughputProperties autoscaleContainerThroughput = container.readThroughput().block().getProperties();

// The autoscale max throughput (RU/s) of the resource
int autoscaleMaxThroughput = autoscaleContainerThroughput.getAutoscaleMaxThroughput();

// The throughput (RU/s) the resource is currently scaled to
int currentThroughput = autoscaleContainerThroughput.Throughput;

Ubah throughput maksimal skala otomatis (RU/s)

// Change the autoscale max throughput (RU/s)
container.replaceThroughput(ThroughputProperties.createAutoscaledThroughput(newAutoscaleMaxThroughput)).block();

Azure Resource Manager

Templat Azure Resource Manager dapat digunakan untuk memprovisikan throughput skala otomatis pada database atau sumber daya tingkat kontainer baru untuk semua Azure Cosmos DB API. Lihat Templat Azure Resource Manager untuk Azure Cosmos DB untuk sampel. Menurut desain, templat Azure Resource Manager tidak dapat digunakan untuk melakukan migrasi antara throughput yang disediakan dan skala otomatis pada sumber daya yang ada.

Azure CLI

Azure CLI dapat digunakan untuk memprovisikan throughput skala otomatis pada database atau sumber daya tingkat kontainer baru untuk semua Azure Cosmos DB AP, atau mengaktifkan skala otomatis pada sumber daya yang ada. Untuk sampel, lihat Sampel Azure CLI untuk Azure Cosmos DB.

Azure PowerShell

Azure PowerShell dapat digunakan untuk memprovisikan throughput skala otomatis pada database atau sumber daya tingkat kontainer baru untuk semua Azure Cosmos DB API, atau mengaktifkan skala otomatis pada sumber daya yang ada. Untuk sampel, lihat Sampel Azure PowerShell untuk Azure Cosmos DB.

Langkah berikutnya