JAN KLEINERT: Key Visualizer for Cloud Spanner
is a tool in the Cloud Console that
helps developers and operations teams analyze Spanner usage
patterns.
It generates visual reports for your databases,
broken down by ranges of rows over time,
and it provides insights into usage patterns at scale
that are difficult to understand otherwise.
I'm going to walk you through how
to use Key Visualizer to look at usage patterns for a Spanner
database that's used by an application I'm working on.
I've recently inherited the responsibility
for this application, and I'm not very familiar with it yet.
First, let's get acquainted with the Key Visualizer interface.
When you access Key Visualizer, you'll see a scan.
The core of a Key Visualizer scan is the heatmap.
The heatmap shows us the value of a metric over time,
broken down into ranges of row keys.
The x-axis represents time, and the y-axis
represents row ranges.
Low values are cold, represented by darker colors like purple,
and high values are hot, represented
by yellow or bright white for the highest values.
The different patterns in the heatmap
can help diagnose issues at a glance.
Each row range represents a contiguous set
of rows in a single table or index.
A row range is defined by a start and end key.
Within each table or index, keys are
sorted by primary key values.
At the top of the heatmap, there's
a key for the heatmap colors.
As you hover over a cell in the heatmap,
you'll see details about the value, timestamp, table,
and key bucket.
You can select a portion of the heatmap to zoom in.
You can also select a time range using the date picker.
You can pan around the heatmap by clicking and dragging.
You can use the select box to change between metrics.
When I look at the graph for number of rows read,
I can see that the reads for keys in the Albums table
are distributed fairly evenly across row ranges.
However, for the Singers table, it's
yellow or hot across the board, and especially
in the beginning row ranges.
After looking at my application code,
I notice the query-singers-last name
function is called frequently.
I can see that we'd probably benefit
from having a secondary index on the LastName field,
so that Spanner doesn't have to scan
the entire table every time query-singers-last name is
called.
We can do this with a CREATE INDEX statement
or by using force index.
I'll make the change and see what happens.
With the application change deployed,
we can see that the number of rows read
has dropped dramatically for the Singers table.
Seeing a single hot table is just one common pattern
you may uncover with Key Visualizer.
Here are some of the other patterns you may encounter
and what issues they might indicate.
A heatmap with a single bright diagonal
line or a triangle with a flat top
can indicate a database that uses sequential keys.
Sequential keys are an antipattern in Spanner,
and you can learn more about why sequential keys cause
hotspots and alternatives in the documentation on schema design
best practices.
A heatmap with horizontal bands of bright color separated
by dark colors indicate that specific row ranges
are consistently being more heavily accessed over time.
To address this, you can consider
changing your schema design or your application
so that the data in a heavily used row
or in an excessively large row is spread across multiple rows.
A heatmap with multiple diagonal bright lines,
either rising or falling, usually
indicates sequential reads or writes
to rows in a short period of time.
If the lines correspond with read activity, such as a table
export, no action is usually required.
If you're experiencing performance issues
during these reads, you can consider
increasing the number of nodes for instance
during those time periods.
If the lines correspond with write activity
and you're experiencing performance issues,
you should consider changing your workload to a random write
instead of a sequential write.
A heatmap showing bright horizontal bands
that appear partway across the heatmap
indicate a sudden change in the usage pattern of a database.
This could be a rogue query or an unexpected surge
in activity for certain rows.
You can learn even more about exploring heatmaps
and understanding heatmap patterns in the Spanner Key
Visualizer documentation.
In this video, we've looked at how Key Visualizer for Spanner
can help you analyze usage patterns in your Spanner
databases.
This tool adds to existing monitoring tools,
such as query stats and monitoring in the Cloud
Console, to help simplify the process of monitoring
and troubleshooting performance issues.
In the description below the video,
you'll find links to the Key Visualizer documentation.
Key Visualizer is now available for all Spanner databases,
so start exploring.