Google Front End (GFE),这是一项对所有 Google Cloud 服务(包括 Spanner)通用的基础架构服务。GFE 会验证所有传输层安全协议 (TLS) 连接是否已停止,并应用保护措施来防范拒绝服务攻击。如需详细了解 GFE,请参阅 Google Front End 服务。
Spanner API 前端 (AFE),用于对 API 请求执行各种检查(包括身份验证、授权和配额检查),并维护会话和事务状态。
Spanner API 请求延迟时间是指 Spanner AFE 收到请求的第一个字节与 Spanner API 前端发送响应的最后一个字节之间的时长(以秒为单位)。此延迟时间包括在 Spanner 后端和 API 层处理 API 请求所需的时间。不过,此延迟时间不包括 Spanner 客户端与服务器之间的网络或反向代理开销。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):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."]]