عمليات معدل النقل (RU/s) باستخدام Azure CLI لقاعدة بيانات أو رسم بياني ل Azure Cosmos DB - API ل Gremlin

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

يقوم البرنامج النصي في هذه المقالة بإنشاء قاعدة بيانات Gremlin مع معدل نقل مشترك ورسم بياني Gremlin مع معدل نقل مخصص، ثم يقوم بتحديث معدل النقل لكل من قاعدة البيانات والرسم البياني. ثم ينتقل البرنامج النصي من القياسي إلى معدل النقل التلقائي ثم يقرأ قيمة معدل النقل التلقائي بعد ترحيله.

المتطلبات الأساسية

  • تتطلب هذه المقالة الإصدار 2.30 أو إصدار أحدث. قم بتشغيل az --version للعثور على الإصدار. إذا كنت بحاجة إلى التثبيت أو الترقية، فراجع تثبيت Azure CLI. إذا كنت تستخدم Azure Cloud Shell، يتم تثبيت أحدث إصدار بالفعل.

نموذج البرنامج النصي

إطلاق Azure Cloud Shell

Azure Cloud Shell هو shell تفاعلية مجانية التي يمكنك استخدامها لتشغيل الخطوات في هذه المقالة. يحتوي على أدوات Azure الشائعة المثبتة مسبقًا والمهيئة للاستخدام مع حسابك.

لفتح Cloud Shell، ما عليك سوى تحديد جربه من الزاوية اليمنى العليا من مجموعة التعليمات البرمجية. يمكنك أيضًا تشغيل Cloud Shell في علامة تبويب مستعرض منفصلة بالانتقال إلى https://shell.azure.com.

عند فتح Cloud Shell، تحقق من تحديد Bash لبيئتك. ستستخدم الجلسات اللاحقة Azure CLI في بيئة Bash، حدد نسخ لنسخ كتل التعليمات البرمجية، وألصقها في Cloud Shell، واضغط على Enter لتشغيلها.

تسجيل الدخول إلى Azure

يُصادق Cloud Shell تلقائياً بموجب الحساب الأولي الذي سُجل الدخول به. استخدم البرنامج النصي التالي لتسجيل الدخول باستخدام اشتراك مختلف، واستبدل <Subscription ID> بمعرّف اشتراك Azure الخاص بك. إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

لمزيد من المعلومات، راجع تعيين اشتراك نشط أو تسجيل الدخول بشكل تفاعلي

تشغيل البرنامج النصي

# Throughput operations for a Gremlin API database and graph

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"
originalThroughput=400
updateThroughput=500

# Create a resource group 
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Gremlin API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableGremlin

# Create Gremlin database with throughput
echo "Creating $database with $originalThroughput"
az cosmosdb gremlin database create --account-name $account --resource-group $resourceGroup --name $database --throughput $originalThroughput

# Create Gremlin graph with throughput 
echo "Creating $graph with $originalThroughput"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey --throughput $originalThroughput

# Throughput operations for Gremlin API database
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned database throughput
az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.throughput -o tsv

# Retrieve the minimum allowable database throughput
minimumThroughput=$(az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.minimumThroughput -o tsv)

echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update database throughput
echo "Updating $database throughput to $updateThroughput"
az cosmosdb gremlin database throughput update --account-name $account --resource-group $resourceGroup --name $database --throughput $updateThroughput

# Migrate the database from standard (manual) throughput to autoscale throughput
az cosmosdb gremlin database throughput migrate --account-name $account --resource-group $resourceGroup --name $database --throughput-type "autoscale"

# Retrieve current autoscale provisioned max database throughput
az cosmosdb gremlin database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.autoscaleSettings.maxThroughput -o tsv

# Throughput operations for Gremlin API graph
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned graph throughput
az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.throughput -o tsv

# Retrieve the minimum allowable graph throughput
minimumThroughput=$(az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update graph throughput
echo "Updating $graph throughput to $updateThroughput"
az cosmosdb gremlin graph throughput update --resource-group $resourceGroup --account-name $account --database $database --name $graph --throughput $updateThroughput

# Migrate the graph from standard (manual) throughput to autoscale throughput
az cosmosdb gremlin graph throughput migrate --account-name $account --resource-group $resourceGroup --database $database --name $graph --throughput-type "autoscale"

# Retrieve the current autoscale provisioned max graph throughput
az cosmosdb gremlin graph throughput show --resource-group $resourceGroup --account-name $account --database $database --name $graph --query resource.autoscaleSettings.maxThroughput -o tsv

تنظيف الموارد

استخدم الأمر التالي لإزالة مجموعة الموارد وجميع الموارد المقترنة بها باستخدام الأمر az group delete - إلا إذا وُجدت حاجة مستمرة لهذه الموارد. قد يستغرق إنشاء بعض هذه الموارد بعض الوقت، وكذلك حذفها.

az group delete --name $resourceGroup

نموذج مرجع

يستخدم هذا البرنامج النصي الأوامر التالية. يرتبط كل أمر في الجدول بأمر وثائق معينة.

الأمر الملاحظات
az group create إنشاء مجموعة موارد يتم تخزين كل الموارد فيها.
إنشاء az cosmosdb ينشئ حساب Azure Cosmos DB.
إنشاء قاعدة بيانات جريملين من az cosmosdb إنشاء Azure Cosmos DB لقاعدة بيانات Gremlin.
إنشاء رسم بياني من az cosmosdb gremlin إنشاء رسم بياني ل Azure Cosmos DB ل Gremlin.
تحديث معدل نقل قاعدة بيانات az cosmosdb gremlin تحديث RU/s لقاعدة بيانات Azure Cosmos DB لقاعدة بيانات Gremlin.
تحديث معدل نقل الرسم البياني az cosmosdb gremlin تحديث RU/s ل Azure Cosmos DB لرسم Gremlin البياني.
معدل النقل بيانات قاعدة بيانات az cosmosdb gremlin ترحيل معدل النقل لقاعدة بيانات Azure Cosmos DB لقاعدة بيانات Gremlin.
معدل النقل الرسم البياني az cosmosdb gremlin ترحيل معدل النقل ل Azure Cosmos DB لرسم Gremlin البياني.
حذف مجموعة az يحذف مجموعة الموارد بما في ذلك جميع الموارد المتداخلة.

الخطوات التالية

لمزيد من المعلومات حول Azure Cosmos DB CLI، راجع وثائق Azure Cosmos DB CLI.