Memecahkan masalah dengan kueri diagnostik tingkat lanjut dengan Azure Cosmos DB untuk Apache Cassandra

BERLAKU UNTUK: Nosql MongoDB Cassandra Gremlin

Dalam artikel ini, kita akan membahas cara menulis kueri yang lebih canggih untuk membantu memecahkan masalah dengan akun Azure Cosmos DB for Cassandra Anda dengan menggunakan log diagnostik yang dikirim ke tabel khusus sumber daya .

Untuk tabel Azure Diagnostics, semua data ditulis ke dalam satu tabel tunggal. Pengguna menentukan kategori mana yang ingin mereka kueri. Jika Anda ingin melihat kueri teks lengkap dari permintaan Anda, lihat Memantau data Azure Cosmos DB menggunakan pengaturan diagnostik di Azure untuk mempelajari cara mengaktifkan fitur ini.

Untuk tabel khusus sumber daya, data ditulis ke dalam tabel individual untuk setiap kategori sumber daya. Kami merekomendasikan mode ini karena:

  • Membuatnya lebih mudah untuk bekerja dengan data.
  • Memberikan penemuan skema yang lebih baik.
  • Meningkatkan performa di latensi penyerapan dan waktu kueri.

Prasyarat

Peringatan

Saat membuat Pengaturan Diagnostik untuk API untuk akun Cassandra, pastikan bahwa "DataPlaneRequests" tetap tidak dipilih. Selain itu, untuk tabel Tujuan, pastikan untuk memilih "Khusus sumber daya" karena menawarkan penghematan biaya yang signifikan dibandingkan "Diagnostik Azure".

Catatan

Perhatikan bahwa mengaktifkan diagnostik teks lengkap, kueri yang ditampilkan akan berisi data PII. Fitur ini tidak hanya akan mencatat kerangka kueri dengan parameter yang disamarkan, tetapi mencatat nilai parameter itu sendiri. Ini dapat berguna dalam mendiagnosis apakah kueri pada Kunci Primer tertentu (atau kumpulan Kunci Primer) mengonsumsi lebih banyak RI daripada kueri pada Kunci Primer lainnya.

Kueri Analitik Log dengan skenario berbeda

Gambar peta kata gelembung dengan kemungkinan pertanyaan tentang cara memanfaatkan Analitik Log dalam Azure Cosmos DB

Konsumsi RU

  • Operasi Cassandra yang menggunakan RU tinggi.

    CDBCassandraRequests 
    | where DatabaseName=="azure_comos" and CollectionName=="user" 
    | project TimeGenerated, RequestCharge, OperationName,
    requestType=split(split(PIICommandText,'"')[3], ' ')[0]
    | summarize max(RequestCharge) by bin(TimeGenerated, 10m), tostring(requestType), OperationName;
    
  • Memantau konsumsi RU per operasi pada kunci partisi logis.

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by PartitionKey, PartitionKeyRangeId
    | order by TotalRequestCharge;
    
    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by OperationName, PartitionKey
    | order by TotalRequestCharge;
    
    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_comos" and CollectionName=="user"
    | summarize TotalRequestCharge=sum(todouble(RequestCharge)) by bin(TimeGenerated, 1m), PartitionKey
    | render timechart;
    
  • Apa kueri teratas yang memengaruhi konsumsi RU?

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where TimeGenerated > ago(24h)
    | project ActivityId, DatabaseName, CollectionName, queryText=split(split(PIICommandText,'"')[3], ' ')[0], RequestCharge, TimeGenerated
    | order by RequestCharge desc;
    
  • Konsumsi RU berdasarkan variasi ukuran payload untuk operasi baca dan tulis.

    // This query is looking at read operations
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName =="SELECT"
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    
    // This query is looking at write operations
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName in ("CREATE", "UPDATE", "INSERT", "DELETE", "DROP")
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    
    // Write operations over a time period.
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName in ("CREATE", "UPDATE", "INSERT", "DELETE", "DROP")
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    | render timechart;
    
    // Read operations over a time period.
    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project ResponseLength, TimeGenerated, RequestCharge, cassandraOperationName=split(split(PIICommandText,'"')[3], ' ')[0]
    | where cassandraOperationName =="SELECT"
    | summarize maxResponseLength=max(ResponseLength), maxRU=max(RequestCharge) by bin(TimeGenerated, 10m), tostring(cassandraOperationName)
    | render timechart;
    
  • Konsumsi RU berdasarkan operasi baca dan tulis oleh partisi logis.

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where OperationName in ("Delete", "Read", "Upsert")
    | summarize totalRU=max(RequestCharge) by OperationName, PartitionKeyRangeId
    
  • Konsumsi RU oleh partisi fisik dan logis.

    CDBPartitionKeyRUConsumption
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | summarize totalRequestCharge=sum(RequestCharge) by PartitionKey, PartitionKeyRangeId;
    
  • Apakah partisi panas menyebabkan konsumsi RU yang tinggi?

    CDBPartitionKeyStatistics
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where  TimeGenerated > now(-8h)
    | summarize StorageUsed = sum(SizeKb) by PartitionKey
    | order by StorageUsed desc
    
  • Bagaimana kunci partisi memengaruhi konsumsi RU?

    let storageUtilizationPerPartitionKey = 
    CDBPartitionKeyStatistics
    | project AccountName=tolower(AccountName), PartitionKey, SizeKb;
    CDBCassandraRequests
    | project AccountName=tolower(AccountName),RequestCharge, ErrorCode, OperationName, ActivityId, DatabaseName, CollectionName, PIICommandText, RegionName
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | join kind=inner storageUtilizationPerPartitionKey  on $left.AccountName==$right.AccountName
    | where ErrorCode != -1 //successful
    | project AccountName, PartitionKey,ErrorCode,RequestCharge,SizeKb, OperationName, ActivityId, DatabaseName, CollectionName, PIICommandText, RegionName;
    

Latensi

  • Jumlah waktu habis sisi server (Kode Status - 408) terlihat di jendela waktu.

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where ErrorCode in (4608, 4352) //Corresponding code in Cassandra
    | summarize max(DurationMs) by bin(TimeGenerated, 10m), ErrorCode
    | render timechart;
    
  • Apakah kita mengamati lonjakan latensi sisi server di jendela waktu yang ditentukan?

    CDBCassandraRequests
    | where TimeGenerated > now(-6h)
    | DatabaseName=="azure_cosmos" and CollectionName=="user"
    | summarize max(DurationMs) by bin(TimeGenerated, 10m)
    | render timechart;
    
  • Operasi yang semakin dibatasi.

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | project RequestLength, ResponseLength,
    RequestCharge, DurationMs, TimeGenerated, OperationName,
    query=split(split(PIICommandText,'"')[3], ' ')[0]
    | summarize max(DurationMs) by bin(TimeGenerated, 10m), RequestCharge, tostring(query),
    RequestLength, OperationName
    | order by RequestLength, RequestCharge;
    

Pembatasan

  • Apakah aplikasi Anda mengalami pembatasan?

    CDBCassandraRequests
    | where RetriedDueToRateLimiting != false and RateLimitingDelayMs > 0;
    
  • Kueri apa yang menyebabkan aplikasi Anda dibatasi dengan periode waktu tertentu khususnya pada 429.

    CDBCassandraRequests
    | where DatabaseName=="azure_cosmos" and CollectionName=="user"
    | where ErrorCode==4097 // Corresponding error code in Cassandra
    | project DatabaseName , CollectionName , CassandraCommands=split(split(PIICommandText,'"')[3], ' ')[0] , OperationName, TimeGenerated;
    

Langkah berikutnya