Profiling Postgres Perils
summary
Practical pitfalls and concrete fixes for profiling Postgres: hardware counters can be invisible in VMs so perf falls back to millisecond timers and gives a different profile; CPU boosting shifts first-run vs later-run throughput (observed up to ~2x clocks) so disable turbo boost for reproducibility; SSD write throughput collapses after a few seconds on consumer drives (one model drops after ~8s, another holds ~70s) so fstrim or over‑provisioning helps; instruction TLB behavior and 2MB alignment of code sections cuts ITLB misses and yields ~5–10% speedups; use perf stat -D DDD, off‑CPU/BPF tools, pin to one core and disable deep idle states to get repeatable results.
AI-written summary · about
chapters (35)
- 0:00Introduction to Postgres profiling
- 1:08Why you profile and reproducibility
- 2:09How performance counters work
- 4:38CPU-bound vs non-CPU-bound workloads
- 6:02Off-CPU profiling tools
- 7:06Memory latency vs CPU cycles
- 9:17Profiling in virtualized environments
- 12:06CPU boosting and thermal throttling
- 15:39Disabling turbo boost
- 18:48Turbo boost impact on bottlenecks
- 19:09SSD write performance degradation
- 21:15Over-provisioning and trimming SSDs
- 22:17Benchmark duration and reproducibility
- 23:03I/O measurement with iostat
- 23:24CPU core speed variations
- 24:08Limiting CPU cores for consistency
- 24:50CPU idle states and performance
- 27:40Disabling CPU idle states
- 29:29Batching to avoid idle states
- 30:53Choosing correct benchmarks
- 31:57Maximizing bottleneck workload proportion
- 34:05Why small improvements are hard to measure
- 36:10Huge pages and ITLB misses
- 38:57Huge page alignment in Postgres
- 41:06Uncontrollable huge page allocation
- 42:30Read-only THP and performance
- 43:11Workaround for huge page variations
- 44:12Analyzing perf reports top-down and bottom-up
- 45:37CPU frequency scaling and code speed
- 46:22Disabling power states for consistency
- 46:42Automation and shell scripts
- 48:05Link time optimization impact
- 49:09Perf vs eBPF tools
- 50:11Hyper-threading considerations
- 51:15Top-down analysis with PMU tools
