Automatic tablet splitting versus manual pre-splitting for range-sharded tables with skewed write distribution
0 reputation · 11 Jul 2021, 04:22 UTC
0 reputation · 11 Jul 2021, 04:22 UTC
For a range-sharded YSQL table keyed on a monotonically increasing identifier, early write traffic concentrates on a small number of tablet leaders until tablet splitting engages. The design goal is to achieve even write distribution across nodes from table creation without incurring unnecessary per-tablet resource overhead.
Two documented approaches address this constraint: automatic tablet splitting, which reactively divides growing tablets under version-sensitive gflag defaults, and manual pre-splitting via SPLIT INTO N or SPLIT AT VALUES, which distributes leaders immediately at the cost of up-front schema design and potential per-tablet memory and compaction overhead.
The concrete constraint involves a skewed key distribution where a minority of tenants generate the majority of writes, raising questions about whether reactive splitting can keep pace or if explicit split points on hot key ranges are preferable.
Additionally, YSQL transaction-isolation-level mapping onto YugabyteDB's snapshot and serializable model has evolved across releases, meaning application retry logic assumptions may silently break after upgrades.
Should automatic tablet splitting under default gflags engage quickly enough to outweigh the per-tablet overhead of manual pre-splitting for a given workload? For skewed range-sharded keys, are explicit SPLIT AT VALUES on hot tenant IDs more effective than SPLIT INTO N? And does re-splitting an already-populated table require a lightweight online operation or a table rebuild?
35275 reputation · 11 Jul 2021, 14:11 UTC
For a range‑sharded YSQL table with a monotonically increasing key and a skewed write pattern (few tenants generate most writes), automatic tablet splitting under the default gflags will eventually engage, but it may not react fast enough to prevent prolonged write concentration on a single tablet. Manual pre‑splitting gives immediate leader distribution, yet it incurs per‑tablet memory and compaction overhead that scales with the number of splits. When the hot‑key ranges are known (e.g., specific tenant IDs), SPLIT AT VALUES on those hot keys is more effective than a uniform SPLIT INTO N because it targets only the congested ranges. Re‑splitting an already‑populated table with SPLIT AT VALUES is an online operation; it does not require a full table rebuild, though it triggers leader reassignment and background compaction rebalancing.
ysql_tablet_split_size_mb (default 64 MiB in recent YugabyteDB releases).SPLIT INTO N creates N tablets immediately, distributing initial write leaders across them.SPLIT AT VALUES splits only at the supplied key values, leaving other ranges untouched.SPLIT AT VALUES to a populated table is processed online; the table remains readable and writable while the split proceeds.Under extreme key skew, a single hot tenant can keep a tablet growing well beyond the split threshold for minutes or hours before the background split process finishes, during which write latency on that tablet may spike. If the workload can tolerate this temporary hotspot, the simpler automatic approach avoids the upfront design effort and the ongoing per‑tablet overhead of many small tablets. Conversely, if write latency must be evenly distributed from the moment the table is created, pre‑splitting (especially SPLIT AT VALUES on the hot tenant IDs) eliminates the initial concentration, at the cost of extra memory for each tablet’s MemStore and increased compaction activity.
yb-admin --master_addresses <master> get_flag ysql_tablet_split_size_mb and ysql_tablet_split_size_threshold_mb.SELECT tablet_id, start_key, end_key, approximate_size_mb
FROM ysql_tablet_history
WHERE table_name = 'your_table'
ORDER BY approximate_size_mb DESC
LIMIT 5;
ALTER TABLE your_table SPLIT AT VALUES ('hot_tenant_id_1'), ('hot_tenant_id_2'), ...;
ysql_tablet_split_size_mb) only after confirming that split frequency does not cause excessive overhead.yb-admin --master_addresses <master> list_tablets <table_id> | grep leader_count
To give a definitive recommendation, we need to know the observed growth rate (size per minute) of the tablet that holds the hot tenant’s writes. If that rate is known, we can compare it to the split threshold and decide whether automatic splitting will engage within your latency tolerance.
# Check split flags
yb-admin --master_addresses 127.0.0.1:7100 get_flag ysql_tablet_split_size_mb
yb-admin --master_addresses 127.0.0.1:7100 get_flag ysql_tablet_split_size_threshold_mb
# Observe tablet sizes for a specific table
SELECT tablet_id, start_key, end_key, approximate_size_mb
FROM ysql_tablet_history
WHERE table_name = 'orders'
ORDER BY approximate_size_mb DESC
LIMIT 10;
# List leader distribution after a split
yb-admin --master_addresses 127.0.0.1:7100 list_tablets <table_id> | awk '/leader/ {print $0}'
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.