This topic describes how to examine a Spanner component to find the source of latency and visualize that latency using OpenCensus. For a high-level overview of the components in this topic, see Latency points in a Spanner request.
Spanner client libraries provide statistics and traces with the use of the OpenCensus observability framework. This framework gives insights into the internals of the client, and aids in troubleshooting end-to-end (round-trip) latency. By default, the framework is disabled.
Before you begin
Use the procedure in Identify the latency point to find the components or components that are showing latency.
Capture and visualize client round-trip latency
Client round-trip latency is the length of time (in milliseconds) between the first byte of the Spanner API request that the client sends to the database (through both the Google Front End (GFE) and the Spanner API front end), and the last byte of response that the client receives from the database.
Capture client round-trip latency
You can capture client round-trip latency for the following languages:
Java
Go
Visualize client round-trip latency
After retrieving the metrics, you can visualize client round-trip latency in Cloud Monitoring.
Here's an example of a graph that illustrates the 5th percentile latency for the client round-trip latency metric. To change the percentile latency to either the 50th or the 99th percentile, use the Aggregator menu.
The program creates an OpenCensus view called roundtrip_latency
.
This string becomes part of the name of the metric when it's exported to Cloud Monitoring.
Capture and visualize GFE latency
Google Front End (GFE) latency is the length of time (in milliseconds) between when the Google network receives a remote procedure call from the client and when the GFE receives the first byte of the response.
Capture GFE latency
You can capture GFE latency for the following languages:
Java
Go
Visualize GFE latency
After retrieving the metrics, you can visualize GFE latency in Cloud Monitoring.
Here's an example of a graph that illustrates the 5th percentile latency for the GFE latency metric. To change the percentile latency to either the 50th or the 99th percentile, use the Aggregator menu.
The program creates an OpenCensus view called gfe_latency
. This
string becomes part of the name of the metric when it's exported to
Cloud Monitoring.
Capture and visualize Spanner API request latency
Spanner API request latency is the length of time (in seconds) between the first byte of a request that the Spanner API frontend receives and the last byte of a response that the Spanner API frontend sends.
Capture Spanner API request latency
By default, this latency is available as part of Cloud Monitoring metrics. You don't have to do anything to capture and export it.
Visualize Spanner API request latency
You can use the Metrics Explorer
charting tool to visualize the graph for the spanner.googleapis.com/api/request_latencies
metric in Cloud Monitoring.
Here's an example of a graph that illustrates the 5th percentile latency for the Spanner API request latency metric. To change the percentile latency to either the 50th or the 99th percentile, use the Aggregator menu.
Capture and visualize query latency
Query latency is the length of time (in milliseconds) that it takes to run SQL queries in the Spanner database.
Capture query latency
You can capture query latency for the following languages:
Java
Go
Visualize query latency
After retrieving the metrics, you can visualize query latency in Cloud Monitoring.
Here's an example of a graph that illustrates the 5th percentile latency for the query latency metric. To change the percentile latency to either the 50th or the 99th percentile, use the Aggregator menu.
The program creates an OpenCensus view called query_stats_elapsed
.
This string becomes part of the name of the metric when it's exported to
Cloud Monitoring.
What's next
Learn more about OpenCensus.
Learn how to use metrics to diagnose latency.