Google Front End (GFE) 是所有 Google Cloud 服務 (包括 Spanner) 共用的基礎架構服務。GFE 會驗證所有傳輸層安全標準 (TLS) 連線是否已停止,並套用防範阻斷服務攻擊的保護措施。如要進一步瞭解 GFE,請參閱 Google Front End Service。
Spanner API 前端 (AFE),可對 API 要求執行各種檢查 (包括驗證、授權和配額檢查),並維護工作階段和交易狀態。
Spanner API 要求延遲時間是指 Spanner AFE 接收要求的第一個位元組,到 Spanner API 前端傳送回應的最後一個位元組之間的時間長度 (以秒為單位)。延遲時間包括在 Spanner 後端和 API 層處理 API 要求所需的時間。不過,這項延遲時間不包括 Spanner 用戶端和伺服器之間的網路或反向 Proxy 額外負擔。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-03 (世界標準時間)。"],[],[],null,["# Latency points in a Spanner request\n\n| **Note:** [OpenCensus is deprecated](https://opentelemetry.io/blog/2023/sunsetting-opencensus/). We recommend using OpenTelemetry to capture and visualize Spanner observability metrics. For more information, see [Capture custom client-side metrics using OpenTelemetry](/spanner/docs/capture-custom-metrics-opentelemetry).\n\nThis page gives an overview of the high-level components involved in a\nSpanner request and how each component can affect latency.\n\nSpanner API requests\n--------------------\n\nThe high-level components that are used to make a Spanner API\nrequest include:\n\n- [Spanner client libraries](/spanner/docs/reference/libraries),\n which provide a layer of abstraction on top of gRPC, and handle server\n communication details, such as session management, transactions, and retries.\n\n- The Google Front End (GFE), which is an infrastructure service that's common\n to all Google Cloud services, including Spanner. The\n GFE verifies that all Transport Layer Security (TLS) connections are stopped\n and applies protections against Denial of Service attacks. To learn more\n about the GFE, see [Google Front End Service](/docs/security/infrastructure/design#google-frontend-service).\n\n- The Spanner API frontend (AFE), which performs various checks\n on the API request (including authentication, authorization, and quota checks)\n , and maintains sessions and transaction states.\n\n- The Spanner database, which executes reads and writes to the\n database.\n\nWhen you make a remote procedure call to Spanner, the\nSpanner client libraries prepare the API request. Then, the API\nrequest passes through both the GFE and the Spanner AFE\nbefore reaching the Spanner database.\n\nBy measuring and comparing the request latencies between different components\nand the database, you can determine which component is causing the problem.\nThese latencies include client round-trip, GFE, Spanner API\nrequest, and query latencies.\n\nThe following sections explain each type of latency you see in the previous\ndiagram.\n\nClient round-trip latency\n-------------------------\n\nClient round-trip latency is the length of time (in milliseconds) between the\nfirst byte of the Spanner API request that the client sends to\nthe database (through both the GFE and the Spanner API front\nend), and the last byte of response that the client receives from the database.\n\nThe [`grpc.io/client/roundtrip_latency`](https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md#default-views)\nmetric provides the time between the first byte of the API request sent to the\nlast byte of the response received.\n\nTo capture and visualize latency for this component, see\n[Capture client round-trip latency with OpenTelemetry](/spanner/docs/capture-custom-metrics-opentelemetry#capture-client-round-trip-latency)\nor [with OpenCensus](/spanner/docs/capture-visualize-latency-opencensus#capture_and_visualize_client_round-trip_latency).\n\nGFE latency\n-----------\n\nGoogle Front End (GFE) latency is the length of time (in milliseconds) between\nwhen the Google network receives a remote procedure call from the client and\nwhen the GFE receives the first byte of the response. This latency doesn't\ninclude any TCP/SSL handshake.\n\nEvery response from Spanner, whether it's REST or gRPC, includes\na header that contains the total time between the GFE and the backend (the\nSpanner service) for both the request and the response. This\nhelps to differentiate better the source of the latency between the client\nand the Google network.\n\nThe `spanner/gfe_latency`\nmetric captures and exposes GFE latency for Spanner requests.\n\nTo capture and visualize latency for this component, see\n[Capture GFE latency with OpenTelemetry](/spanner/docs/capture-custom-metrics-opentelemetry#capture-gfe-latency)\nor [with OpenCensus](/spanner/docs/capture-visualize-latency-opencensus#capture_and_visualize_gfe_latency).\n\nSpanner API request latency\n---------------------------\n\nSpanner API request latency is the length of time (in seconds)\nbetween the first byte of request that the Spanner AFE\nreceives and the last byte of response that the Spanner API\nfrontend sends. The latency includes the time needed for processing API\nrequests in both the Spanner backend and the API layer.\nHowever, this latency doesn't include network or reverse-proxy overhead\nbetween Spanner clients and servers.\n\nThe `spanner.googleapis.com/api/request_latencies` metric captures\nand exposes Spanner AFE latency for\nSpanner requests.\n\nTo capture and visualize latency for this component, see\n[Capture Spanner API request latency with OpenTelemetry](/spanner/docs/capture-custom-metrics-opentelemetry#capture-spanner-api-request-latency)\nor [with OpenCensus](/spanner/docs/capture-visualize-latency-opencensus#capture_and_visualize_api_request_latency).\n\nQuery latency\n-------------\n\nQuery latency is the length of time (in milliseconds) that it takes to run SQL\nqueries in the Spanner database.\n\nQuery latency is available for the [executeSql](/spanner/docs/reference/rpc/google.spanner.v1#ExecuteSqlRequest) API.\n\nIf the [`QueryMode`](/spanner/docs/reference/rpc/google.spanner.v1#querymode)\nparameter is set to `WITH_STATS` or `WITH_PLAN_AND_STATS`, then Spanner's\n[`ResultSetStats`](/spanner/docs/reference/rpc/google.spanner.v1#resultsetstats)\nare available in the responses. `ResultSetStats` includes the elapsed time for running queries in\nthe Spanner database.\n\nTo capture and visualize latency for this component, see\n[Capture query latency with OpenTelemetry](/spanner/docs/capture-custom-metrics-opentelemetry#capture-query-latency)\nor [with OpenCensus](/spanner/docs/capture-visualize-latency-opencensus#capture_and_visualize_query_latency).\n\nWhat's next\n-----------\n\n- Learn how to [identify latency points](/spanner/docs/identify-latency-point) in Spanner components."]]