Summary “Five Steps to Make Your Go Code Faster & More Efficient” FOSDEM 04.02.2023 by Bartek Plotka
Summary of the ‘Efficient Go’ Book. Story from Thanos project inspired it.
First Thanos compactor was implemented not very optimized and with increased usage in different companies issues started arising with memory overuse, OOM, etc.
- Add an option to use less memory. But Go is not Java, it’s already quite effective
- Vertical scale up. Waste of money 💰
- Horizontal scale out. Complexity of service became huge
- Use other solutions, like Cortex, Mimi’s, etc
- Switch to vendor solution
Meanwhile code is not effective and this is the main issue. Finally, compactor code was reviewed and algorithm optimized.
In the past, in lots of cases code was over optimized from the beginning. But now with all elasticity of clouds and orchestrators optimizations are happening often later.
Five pragmatic steps towards more efficient Go programs
- Use TFBO test/fix/benchmark/optimize. Which is TDD wrapped with BDO.
- Understand current efficiency level with micro benchmarks. Using embedded go benchmark framework. It has different options and results should be reproducible. Use benchstat tool to get human readable results from benchmarks.
- Understand your efficiency requirements. To not start with premature optimizations. RAER (resource aware efficiency requirements). Try to estimate roughly requirements.
- Focus on hot path. Using profiling. Adding couple options to the same benchmark command line for cpu and memory. And then check in flamegraphs where cpu is spend.
- Optimize and repeat.
Link to presentation page where video and presentation will be added https://fosdem.org/2023/schedule/event/gofivestepsefficient/