本頁說明如何計算串流和區隔要求的 Spanner API 要求延遲時間。
您可以使用 AuditLog
的 metadata
結構體物件中的欄位,計算 Spanner API 串流和分區要求的延遲時間。中繼資料的類型為 QueryPerformanceMetadata
。對於串流和分區要求,metadata
不包含 processingSecondsDuration
欄位。如要瞭解如何使用 processingSecondsDuration
計算所有其他要求類型的要求延遲時間,請參閱「處理時間」。
要求串流要求的延遲時間
當用戶端傳送串流要求,並且 Spanner API 傳回部分結果集時,Cloud 稽核記錄會記錄第一個和最後一個回應的稽核記錄。串流要求的延遲時間,是指 Spanner API 收到要求與用戶端收到最後回應之間的時間間隔。
辨識串流要求稽核記錄項目
如要計算串流要求的要求延遲時間,您必須找出與要求相關的記錄項目。記錄項目的 protoPayload.methodName
已設為 google.spanner.v1.Spanner.ExecuteStreamingSql
或 google.spanner.v1.Spanner.StreamingRead
。每個串流要求都有兩個記錄項目,並按 operation.id
分組。第一個項目將 operation.first
設為 true
,最後一個項目將 operation.last
設為 true
。系統也會填入 protoPayload.metadata.responseTimestamp
物件。
計算串流要求的延遲時間
如要計算串流要求的延遲時間,請依 operation.id
篩選稽核記錄。最新的 protoPayload.metadata.responseTimestamp
和最早的 protoPayload.requestMetadata.requestAttributes.time
之間的差異就是要求延遲時間。
串流要求的稽核記錄範例
如要查看串流要求的所有記錄項目,請在記錄檔探索工具中執行以下查詢,並將 OPERATION_ID 變數替換為所需的值:
operation.id="OPERATION_ID"
以下範例會尋找串流要求的記錄項目,該要求的 operation.id
為 15327696495839874591
:
operation.id="15327696495839874591"
已傳回第一個記錄
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {...},
"requestMetadata": {
"requestAttributes": {
"time": "2023-02-27T16:57:40.552952297Z",
},
"destinationAttributes": {}
},
"serviceName": "spanner.googleapis.com",
"methodName": "google.spanner.v1.Spanner.ExecuteStreamingSql",
"authorizationInfo": [{...}],
"resourceName": "projects/example-project/instances/example-instance/databases/example-database/sessions/example-session",
"request": {
"session": "projects/example-project/instances/example-instance/databases/example-database/sessions/example-session",
"requestOptions": {},
"sql": "SELECT COUNT(*) as count FROM Example_table WHERE Example_Column > @timestamp",
"@type": "type.googleapis.com/google.spanner.v1.ExecuteSqlRequest",
"queryOptions": {}
},
"metadata": {
"@type": "type.googleapis.com/spanner.cloud.instance_v1.QueryPerformanceMetadata",
"responseTimestamp": "2023-02-27T16:57:40.555730699Z"
}
},
"insertId": "h7fj0jei6597",
"resource": {...},
"timestamp": "2023-02-27T16:57:40.552391554Z",
"severity": "INFO",
"logName": "projects/example-project/logs/cloudaudit.googleapis.com%2Fdata_access",
"operation": {
"id": "15327696495839874591",
"producer": "spanner.googleapis.com",
"first": true
},
"receiveTimestamp": "2023-02-27T16:57:41.507770020Z"
}
傳回上次記錄
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {...},
"requestMetadata": {
"requestAttributes": {
"time": "2023-02-27T16:57:40.552952297Z",
},
"destinationAttributes": {}
},
"serviceName": "spanner.googleapis.com",
"methodName": "google.spanner.v1.Spanner.ExecuteStreamingSql",
"authorizationInfo": [{...}],
"resourceName": "projects/example-project/instances/example-instance/databases/example-database/sessions/example-session",
"metadata": {
"responseTimestamp": "2023-02-27T16:57:40.556138125Z",
"@type": "type.googleapis.com/spanner.cloud.instance_v1.QueryPerformanceMetadata"
}
},
"insertId": "h7fj0jei6598",
"resource": {...},
"timestamp": "2023-02-27T16:57:40.552391554Z",
"severity": "INFO",
"logName": "projects/example-project/logs/cloudaudit.googleapis.com%2Fdata_access",
"operation": {
"id": "15327696495839874591",
"producer": "spanner.googleapis.com",
"last": true
},
"receiveTimestamp": "2023-02-27T16:57:41.507770020Z"
}
要求延遲時間是最新的 metadata.responseTimestamp
減去最早的 requestAttributes.time
。結果為 2023-02-27T16:57:40.556138125Z-2023-02 - 2023-02-27T16:57:40.552952297Z,等於 0.003185828 秒。
分區要求的請求延遲時間
當用戶端傳送分割要求時,Spanner 會建立多個稽核記錄。如要計算端對端分區要求和後續對分區的呼叫的請求延遲時間,請找出與父項要求相關聯的稽核記錄。
辨識分區要求稽核記錄項目
您發出 PartitionRead
或 PartitionQuery
要求時,系統會在 PartitionResponse
中傳回一組區隔。當您分別為每個分區發出 Read
、ExecuteSql
或 ExecuteStreaming
呼叫時,Spanner 會記錄這些方法的稽核記錄。每個記錄都包含一個 ID,用於將記錄分組,稱為 protoPayload.metadata.partitionBatchIdentifier
。系統也會填入 protoPayload.metadata.responseTimestamp
物件。
計算分區要求的請求延遲時間
如要計算分區要求的請求延遲時間,您可以依 metadata.partitionBatchIdentifier
篩選稽核記錄。最新的 metadata.responseTimestamp
和最早的 protoPayload.requestMetadata.requestAttributes.time
之間的差異就是要求延遲時間。
分割區要求的稽核記錄範例
如要查看分割區要求的所有記錄項目,請在記錄檔探索工具中執行以下查詢,並將 PARTITION_BATCH_ID 變數替換為所需的值:
metadata.partitionBatchIdentifier="PARTITION_BATCH_ID"
以下範例會尋找分區要求的記錄項目,metadata.partitionBatchIdentifier
為 15327696495839874591
:
metadata.partitionBatchIdentifier="15327696495839874591"
已傳回第一個記錄
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {...},
"requestMetadata": {
"requestAttributes": {
"time": "2023-02-15T18:13:39.341584693Z",
},
},
"serviceName": "spanner.googleapis.com",
"methodName": "google.spanner.v1.Spanner.ExecuteStreamingSql",
"authorizationInfo": [{...}],
"resourceName": "projects/example-project/instances/example-instance/databases/example-db/sessions/example-session",
"request": {...},
"metadata": {
"@type": "type.googleapis.com/spanner.cloud.instance_v1.QueryPerformanceMetadata",
"partitionBatchIdentifier": "4841471066190013455",
"responseTimestamp": "2023-02-15T18:13:39.343693061Z"
}
},
"insertId": "4fug42dqke5",
"resource": {...},
"timestamp": "2023-02-15T18:13:39.341069413Z",
"severity": "INFO",
"logName": "projects/example-project/logs/cloudaudit.googleapis.com%2Fdata_access",
"operation": {...},
"receiveTimestamp": "2023-02-15T18:13:39.983812511Z"
}
傳回的第二個記錄
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {...},
"requestMetadata": {
"requestAttributes": {
"time": "2023-02-15T18:13:39.341584693Z",
},
},
"serviceName": "spanner.googleapis.com",
"methodName": "google.spanner.v1.Spanner.ExecuteStreamingSql",
"authorizationInfo": [{...}],
"resourceName": "projects/example-project/instances/example-instance/databases/example-db/sessions/example-session",
"metadata": {
"responseTimestamp": "2023-02-15T18:13:39.344256101Z",
"partitionBatchIdentifier": "4841471066190013455",
"@type": "type.googleapis.com/spanner.cloud.instance_v1.QueryPerformanceMetadata"
}
},
"insertId": "4fug42dqke6",
"resource": {...},
"timestamp": "2023-02-15T18:13:39.341069413Z",
"severity": "INFO",
"logName": "projects/example-project/logs/cloudaudit.googleapis.com%2Fdata_access",
"operation": {...},
"receiveTimestamp": "2023-02-15T18:13:39.983812511Z"
}
視分區數量而定,Spanner 記錄的記錄檔可能會比本範例多。
傳回上次記錄
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo": {...},
"requestMetadata": {
"requestAttributes": {
"time": "2023-02-15T18:13:39.439207331Z",
},
},
"serviceName": "spanner.googleapis.com",
"methodName": "google.spanner.v1.Spanner.ExecuteStreamingSql",
"authorizationInfo": [{...}],
"resourceName": "projects/example-project/instances/example-instance/databases/example-db/sessions/example-session",
"metadata": {
"partitionBatchIdentifier": "4841471066190013455",
"@type": "type.googleapis.com/spanner.cloud.instance_v1.QueryPerformanceMetadata",
"responseTimestamp": "2023-02-15T18:13:39.441692339Z"
}
},
"insertId": "4fug42dqkec",
"resource": {...},
"timestamp": "2023-02-15T18:13:39.438607931Z",
"severity": "INFO",
"logName": "projects/example-project/logs/cloudaudit.googleapis.com%2Fdata_access",
"operation": {...},
"receiveTimestamp": "2023-02-15T18:13:39.983812511Z"
}
要求延遲時間是最新的 metadata.responseTimestamp
減去最早的 requestAttributes.time
。結果為 2023-02-15T18:13:39.441692339Z - 2023-02-15T18:13:39.341584693Z,等於 0.100107646 秒。