Does InfluxDB write latency to a single shard degrade predictably under concurrent writers?
0 reputation · 27 Mar 2023, 10:24 UTC
0 reputation · 27 Mar 2023, 10:24 UTC
I am planning capacity for an InfluxDB deployment where many clients write points that land in the same shard concurrently. My understanding is that writes to one shard contend on the TSM writer lock, so per-point latency should rise with concurrency, but I have not found guidance on whether that degradation is roughly linear, threshold-based, or tied to compaction triggering at the same time.
The relevant constraints: assume InfluxDB 1.x TSM storage (I am aware 1.x and 2.x differ here and would want version-specific answers), batch writes from dozens of concurrent clients, and node-local metrics such as TSM write latency and the debug queries endpoint available for observation. The uncertainty is how much of the latency increase is lock contention versus simultaneous shard group compaction, given that the compaction trigger threshold is not publicly documented and varies by TSM version.
Specifically: does per-point write latency to a single shard grow predictably with concurrent writer count, or does it spike only once compaction kicks in? Which node-local metrics best separate lock contention from compaction delay? Is there a documented concurrency level at which splitting writes across shards (e.g., via shard group duration tuning) becomes the recommended mitigation?
32775 reputation · 27 Mar 2023, 19:13 UTC
For InfluxDB 1.x TSM, per-point write latency to a single shard degrades gradually with concurrent writer count due to per-shard lock contention, and then spikes whenever a cache snapshot/flush or a TSM compaction in the same shard group runs. It is neither purely linear nor purely threshold-based – expect a rising baseline with periodic spikes, i.e., a bimodal latency distribution.
What is well established for 1.x TSM:
cache-max-memory-size, cache-snapshot-memory-size), a forced snapshot/flush produces a pronounced latency spike.What is not established: any fixed concurrency number at which degradation becomes unacceptable, and the exact compaction trigger thresholds. Both vary by 1.x minor version, config, and hardware, so treat any specific threshold you see quoted as workload-dependent, not a documented constant.
The two causes have different signatures in node-local metrics:
snapshotCount and resets of cacheAgeMs in the per-shard tsm1 stats.Poll /debug/vars every few seconds during a load test and log the tsm1 per-shard cache and compaction counters alongside client-side latency percentiles. Correlating spike timestamps with snapshots versus compaction activity attributes the delay. The _internal monitor database exposes similar counters, but note it adds write load itself and can slightly worsen contention on a saturated node — prefer /debug/vars for measurement.
Batch size first. Larger batches amortize lock acquisition and WAL fsync; dozens of clients sending tiny batches degrade faster than the same throughput in fewer, larger batches. This often flattens the curve without any schema change.
Shard group duration second. Shortening it (e.g., 7d → 1d, or hours for very high throughput) spreads concurrent writes across more shards and makes compactions touch smaller files. There is no documented concurrency level at which this becomes the recommended step — it is the standard mitigation once batching is maxed out and p99 is still dominated by single-shard contention. The trade-off is more shards and files to manage, and it only helps if your writes actually span the new shard boundaries.
Validate whichever change you pick by re-running the same load test and confirming p99 flattens before applying it in production.
All of this is specific to InfluxDB 1.x TSM. 2.x and especially 3.x use different storage engines, so do not extrapolate. Exact compaction thresholds and queue behavior vary across 1.x minor versions and config (compact-throughput, cache sizes) — verify against your version's release notes before tuning.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.