Optimizing Go for Clouds
summary
Kubelet metric collection wastes CPU and GC time by allocating 5k DTO metrics on every scrape, producing ~8 MB and ~200k heap allocations per collect; goal is to cut allocations to about the raw data size. Reproduction uses Go microbenchmarks, pprof and benchstat to measure and compare. Fixes include caching DTOs, pre-allocating and reusing slices, and correcting label-sorting to avoid churn. Results drop allocations to <1MB / 25k allocations for 5k metrics and land within scrape timing.
AI-written summary · about
chapters (63)
- 0:00Introduction
- 0:53Who am I
- 1:54Why this topic
- 3:57Outline
- 4:20Theory
- 4:49Speed Efficiency
- 4:59Efficiency
- 6:55Efficiency Speed
- 7:17Counter Arguments
- 7:54Why would you optimize
- 10:12Now hearing all of this
- 10:26Optimization kills readability
- 11:44Premature optimization
- 12:02Hardware is getting faster
- 14:37Scale horizontally
- 14:47Multithreaded
- 15:18Time to market
- 15:41Go is efficient
- 17:12Datadriven decisions
- 17:25Optimization challenges
- 19:55Open source issue on Kubernetes
- 22:11Optimizing Kubernetes
- 26:12Test Driven Development
- 27:05Benchmark Driven Optimization
- 28:15Macro Benchmarks
- 29:44Benchmark Tool
- 32:12Test Data
- 33:40Compilation
- 34:40Global Variable
- 35:14Benchmarks
- 36:02Understanding the results
- 39:10Finding bottlenecks
- 39:54Pprov
- 41:14Malloc
- 41:31Garbage Collection
- 41:52Share Polar Signals
- 42:19Memory
- 43:08Magic Graph
- 43:35Prometheus Process Metric
- 43:57Peak
- 44:16Collect
- 45:44Algorithm Level Optimization
- 47:10Complexity
- 47:44Cache
- 48:52Race
- 49:22Single Flight
- 50:16Implementation
- 50:36Benchstat
- 51:03Collect Container Info
- 51:28String Slice
- 51:43Array Slice
- 53:31Preallocate
- 55:06Magic values
- 55:41Results
- 56:02Add Metric
- 56:29Debug
- 56:40C Advisor
- 56:55Client Golang
- 57:39Finally
- 58:11Documentation
- 59:01Pattern
- 59:23Summary
- 59:38Learning
related talks
19mHeap Optimization for Go Systems
51mObscure Go Optimisations
14mOptimizing Go code without a blindfold
40mGolang memory footprint
46mSimplifying Scalable Cloud Application Development with Go
48mGolang's Garbage
51mEvolving the Go Memory Manager's RAM and CPU Efficiency
56mThe Key to Go Efficiency is Just a Few Go Runtime Metrics Away!
