Tablets, Hotspots, Key Visualizer and Throughput

Article · 8:00

Tablet splitting and rebalancing, diagnosing a hotspot, Key Visualizer, the read and write cost model, per-node limits and throughput testing.

This lesson has 1 runnable example. Press Try yourself! under any of them to open it in the editor.

Tablets split and move automatically, and understanding when is what makes the performance model predictable. Bigtable splits a tablet when it grows large or receives disproportionate traffic, and moves tablets between nodes to balance load. Two things follow. First, rebalancing takes time - minutes to tens of minutes - so a sudden change in traffic shape is served badly until the rebalance completes, and a benchmark that ramps instantly measures the rebalance rather than the steady state. Second, a row is never split, so an oversized row pins a tablet that cannot be divided.

Pre-splitting is available at table creation, by supplying initial split keys. It is genuinely useful when you know the key distribution in advance and are about to load a lot of data, because it avoids the load being served by one tablet while splits catch up.

Diagnosing a hotspot follows a specific path, and the distinction at the end is the point:

  1. Latency is bad, or throughput plateaus below expectations.
  2. Check CPU: Bigtable reports average and maximum per-node CPU. A high maximum with a low average is a hotspot; both high is insufficient capacity.
  3. Open Key Visualizer and look at the heat map.
  4. Fix the key, or add nodes - and these are different fixes for different problems, which is why step 2 matters.

Key Visualizer is the single most useful diagnostic in this programme. It renders your key space on the vertical axis against time on the horizontal, with colour showing activity - reads, writes, CPU, row size. A hotspot appears as a bright horizontal line: one narrow key range taking all the traffic while the rest of the space is dark. A sequential key appears as a diagonal: the hot range moving steadily up the key space over time. Learning to read those two patterns is worth more than any amount of reasoning about key design in the abstract.

The cost model. Bigtable bills nodes per hour, storage per GB-month (SSD costing more than HDD), and network egress. Notably it does not bill per request, which makes it different from DynamoDB and Firestore - the cost is the capacity you provision, so an inefficient scan costs you latency and node count rather than a line on an invoice. The consequence: your cost model is a node count, and your node count comes from throughput and storage, both of which you must measure.

Per-node throughput is roughly 10,000 small-row reads or writes per second on SSD, and you rarely achieve it because: reads of large rows cost more, filters still read, a hotspot means one node is doing the work, and the replication factor multiplies write cost. Throughput testing must therefore use realistic row sizes and a realistic key distribution, or it measures nothing useful.

Laboratory exercise 4 - a measured improvement.

On a real instance, load at least fifty million rows. Declare a baseline: five operations with p50, p95 and p99, plus average and maximum per-node CPU for each.

Create a hotspot deliberately with a timestamp-leading key and drive writes at it. Record: throughput plateauing, maximum node CPU near 100% with average low, and the Key Visualizer diagonal. Capture the image. Then switch to a field-promoted key and capture the Key Visualizer again - the before-and-after images are the module's main artefact.

Demonstrate the rebalance delay: change your traffic shape suddenly and measure how long until latency recovers.

Demonstrate pre-splitting: load the same data into a table with and without initial split keys, and compare the load time and latency during the load.

Compare read patterns and record the cost of each: a point lookup, a 100-row range scan, a 100,000-row range scan, the same with a StripValueTransformerFilter, and a value filter over a large range.

Then the node scaling experiment: measure throughput at 1, 3 and 6 nodes with a well-distributed key, and then with a hotspotting key. The first should scale roughly linearly; the second should not scale at all, which is the demonstration that a hotspot is not a capacity problem.

Deliverable: the benchmark report with average and maximum node CPU at each step, the Key Visualizer images before and after the key fix, the rebalance delay measurement, the pre-splitting comparison, the read pattern cost table, the node scaling results for both key designs, and a cost model derived from the measured node count.

PY Example 1 169 lines
# ==================================================================
# TABLETS: split and moved automatically. Know when.
# ==================================================================
# Bigtable splits a tablet when it grows large OR receives
# DISPROPORTIONATE TRAFFIC, and moves tablets between nodes to
# balance load.
#
# TWO CONSEQUENCES:
#  1. *** REBALANCING TAKES TIME *** - minutes to tens of minutes.
#     So a sudden change in traffic shape is SERVED BADLY until it
#     completes, and a BENCHMARK THAT RAMPS INSTANTLY MEASURES THE
#     REBALANCE, not the steady state. Warm up, then measure.
#  2. *** A ROW IS NEVER SPLIT. *** An oversized row pins a tablet
#     that CANNOT BE DIVIDED, and nothing can fix that but changing
#     the schema.

# PRE-SPLITTING at creation, when you know the distribution and are
# about to load a lot:
#   cbt createtable telemetry \
#     families=cur:maxversions=1,hist:maxage=90d \
#     splits=dev#d-1,dev#d-2,dev#d-3,dev#d-4,dev#d-5,dev#d-6,dev#d-7
#
# Without it, the initial load is served by ONE TABLET while splits
# catch up - which is slow, and looks like a hotspot because it is
# one. Measure both in the lab.

# ==================================================================
# *** DIAGNOSING A HOTSPOT. The distinction at step 2 is the point. ***
# ==================================================================
#  1. latency is bad, or throughput plateaus below expectations
#
#  2. CHECK CPU. Bigtable reports BOTH:
#       bigtable.googleapis.com/cluster/cpu_load            (average)
#       bigtable.googleapis.com/cluster/cpu_load_hottest_node (MAX)
#
#     *** HIGH MAXIMUM, LOW AVERAGE  = A HOTSPOT.
#     ***                              Adding nodes WILL NOT HELP.
#     *** BOTH HIGH                  = INSUFFICIENT CAPACITY.
#     ***                              Adding nodes WILL help.
#
#     cpu_load 0.22, cpu_load_hottest_node 0.97   -> hotspot
#     cpu_load 0.88, cpu_load_hottest_node 0.91   -> add nodes
#
#     Getting that distinction wrong means paying for nodes that do
#     nothing, which is the most common Bigtable misdiagnosis.
#
#  3. OPEN KEY VISUALIZER.
#  4. fix the key, OR add nodes - DIFFERENT FIXES FOR DIFFERENT
#     PROBLEMS, which is why step 2 exists.

# ==================================================================
# *** KEY VISUALIZER. The most useful diagnostic in this programme. ***
# ==================================================================
#   Console -> Bigtable -> your table -> Key Visualizer
#   (a real instance only - the emulator has none, and it needs
#    about 30 GB of data and some hours of traffic to generate)
#
#   The heat map: KEY SPACE on the vertical axis, TIME on the
#   horizontal, colour = activity. Metrics: Ops, Read/Write bytes,
#   CPU, Row size, Max row size.
#
#   THE TWO PATTERNS TO LEARN:
#
#   A BRIGHT HORIZONTAL LINE
#     one narrow key range taking all the traffic, the rest dark
#     -> a hot KEY or key range. A single device, a single
#        low-cardinality prefix, a "current" row everything updates.
#
#   A BRIGHT DIAGONAL
#     the hot range moving steadily UP the key space over time
#     -> A SEQUENTIAL KEY. This is the timestamp-leading signature,
#        and once you have seen it you recognise it instantly.
#
#   Learning to read those two is worth more than any amount of
#   abstract reasoning about key design. CAPTURE BOTH IMAGES - before
#   the key fix and after - as the module's main artefact.

# ==================================================================
# THE COST MODEL: nodes, storage, egress. NOT per request.
# ==================================================================
#   NODES        per node-hour, per cluster
#   STORAGE      per GB-month; SSD costs more than HDD
#   EGRESS       network out
#   backups      storage
#   replication  the second cluster's NODES AND STORAGE, in full
#
#   *** THERE IS NO PER-REQUEST CHARGE. *** Unlike DynamoDB and
#   Firestore, an inefficient scan costs you LATENCY AND NODE COUNT,
#   not a line on an invoice.
#
#   SO YOUR COST MODEL IS A NODE COUNT, and the node count comes from
#   THROUGHPUT and STORAGE - both measured:
#
#     throughput: 180,000 writes/s + 40,000 reads/s
#                 / ~10,000 per node (SSD, small rows)
#                 = 22 nodes  ... IF perfectly distributed
#                 + headroom for the hottest node
#                 = 28 nodes
#     storage:    40 TB / (per-node SSD limit)
#                 = whichever is larger
#     x2 for a second cluster, if replicating
#
#   The "IF perfectly distributed" is where Module 2 pays for itself:
#   a hotspotting key means the effective per-node rate is a
#   fraction of 10,000 and the node count is a fiction.

# ==================================================================
# PER-NODE THROUGHPUT, and why you rarely get it.
# ==================================================================
#   ~10,000 small-row reads OR writes per second per node, on SSD.
#   You rarely achieve it because:
#     * large rows cost more per operation
#     * FILTERS STILL READ the rows (Module 2)
#     * A HOTSPOT means one node is doing the work
#     * REPLICATION multiplies write cost
#     * a scan returning many cells per row costs per CELL, not per row
#
# *** SO THROUGHPUT TESTING MUST USE REALISTIC ROW SIZES AND A
# *** REALISTIC KEY DISTRIBUTION, or it measures nothing. *** A
# benchmark with uniform random keys and 50-byte rows will tell you
# the instance is wonderful and your production workload will not
# agree.

# Read pattern costs - the table to produce:
#   point lookup (1 row)                      p99 ___ ms   ___ cells
#   range scan, 100 rows                      p99 ___ ms   ___ cells
#   range scan, 100,000 rows                  p99 ___ ms   ___ cells
#   same + StripValueTransformerFilter        p99 ___ ms   ___ cells
#   value filter over 1,000,000 rows          p99 ___ ms   ___ cells
#                                             ^^ reads a million,
#                                                returns a handful
import time
from google.cloud.bigtable import row_filters as rf

t0 = time.perf_counter()
rows = list(table.read_rows(row_set=_prefix("dev#d-0042#2026113014"),
                            filter_=rf.CellsColumnLimitFilter(1)))
elapsed = time.perf_counter() - t0

# A CHEAP EXISTENCE SCAN: keys and qualifiers only, no values.
rows = table.read_rows(row_set=_prefix("dev#"),
                       filter_=rf.StripValueTransformerFilter(True))
# Genuinely much cheaper on bytes returned - though it still READS
# the rows, as Module 2 established.

# ==================================================================
# *** THE NODE SCALING EXPERIMENT. The module's conclusion. ***
# ==================================================================
#   gcloud bigtable clusters update prod-c1 --instance=telemetry \
#     --num-nodes=6
#
#   WELL-DISTRIBUTED key (field-promoted):
#     1 node   ~10,000 writes/s
#     3 nodes  ~29,000 writes/s      <- roughly LINEAR
#     6 nodes  ~57,000 writes/s
#
#   HOTSPOTTING key (timestamp-leading):
#     1 node   ~10,000 writes/s
#     3 nodes  ~10,000 writes/s      <- NO IMPROVEMENT AT ALL
#     6 nodes  ~10,000 writes/s
#
# *** THAT IS THE DEMONSTRATION: A HOTSPOT IS NOT A CAPACITY
# *** PROBLEM, AND NO AMOUNT OF MONEY FIXES IT. *** Run it, record
# the numbers, and keep them - it is the argument you will need to
# make to someone who wants to add nodes.
#
# Also allow time after scaling: Bigtable REBALANCES TABLETS onto
# the new nodes, which takes minutes. Measure immediately after and
# twenty minutes later, and report both.

Open this example in the editor and change it. Nothing you type is saved.

Discussion

No questions on this topic yet. Sign in to ask the first one.