Performance Tuning
Identify Your Workload
| Workload | Characteristics | Primary Tuning Focus |
|---|---|---|
| OLTP (read-heavy) | Many point reads, few writes | Cache sizes, bloom filters |
| OLTP (write-heavy) | High write throughput, fewer reads | Memtable size, shard count, WAL batching |
| Mixed | Both reads and writes | Balanced configuration |
| Analytical | Large scans, aggregations | Block size, compaction |
| Time-series | Append-only, temporal queries | Write batching, compaction thresholds |
Read Optimization
Increase Cache Sizes
config.block_cache_bytes = 128 * 1024 * 1024; // 128MBconfig.index_cache_entries = 4096;Monitor with EXPLAIN ANALYZE — if cache_hits is low, increase cache.
Optimize Bloom Filters
config.bloom_bits_per_key = 14; // ~0.2% false positive rateHigher bits per key reduces false positives but increases memory usage.
Reduce Read Amplification
config.compaction_l0_threshold = 4; // Compact L0 soonerFewer L0 files means fewer files to check on reads.
Write Optimization
Enable Fast Write Path
config.fast_write_enabled = true; // DefaultIncrease Batch Window
config.fast_write_wal_batch_interval_us = 2000; // 2ms batchLarger batch windows amortize fsync cost across more writes.
Larger Memtable
config.memtable_max_bytes = 16 * 1024 * 1024; // 16MBFewer flushes mean less write amplification.
More Shards
config.shard_count = 8; // More parallelismMonitoring
SHOW Commands
TensorDB provides 5 diagnostic SQL commands for monitoring:
SHOW STATS; -- Uptime, puts/gets, cache hit rate, query latency histogramSHOW SLOW QUERIES; -- Recent slow queries with duration and row countsSHOW ACTIVE QUERIES; -- Currently running queries with elapsed timeSHOW STORAGE; -- Per-shard memtable/SSTable/WAL breakdownSHOW COMPACTION STATUS; -- L0 file counts, level sizes, compaction needsThe slow query threshold is configurable via slow_query_threshold_us (default: 10ms).
Health Endpoint
When running tensordb-server, a health HTTP endpoint is available on port+1:
curl http://localhost:5434/health | jq .# {"status":"healthy","uptime_ms":12345,"shard_count":4,...}EXPLAIN ANALYZE
EXPLAIN ANALYZE SELECT * FROM users WHERE id = 'u1';Key metrics:
execution_time_us: Total query timecache_hits: Block cache hit countbloom_filter_hits: Bloom filter positive countrows_returned: Result set size
Common Tuning Scenarios
Slow Point Reads
- Check
bloom_filter_hits— increasebloom_bits_per_keyif high - Check
cache_hits— increaseblock_cache_bytesif low - Check L0 file count — reduce
compaction_l0_thresholdif high
Slow Writes
- Verify fast write path is enabled
- Increase
fast_write_wal_batch_interval_us - Increase
memtable_max_bytesto reduce flush frequency - Increase
shard_countfor more parallelism
High Memory Usage
- Reduce
block_cache_bytes - Reduce
memtable_max_bytes - Reduce
index_cache_entries - Reduce
bloom_bits_per_keyto minimum (4)
High Disk Usage
- LZ4 compression reduces on-disk size by ~2x
- Adjust
compaction_size_ratiofor more aggressive compaction - Review data retention policies