Profiling & Optimizing Go Training
Go ships with amazing profiling tools, but understanding how and when to use them, as well as understanding their output, can be quite challenging. This course was designed to take experienced developers through the fundamentals of the pprof tool, and show them how to and when to create proper profiles for their code. It then shows them how to spot performance issues, identifies common performance pitfalls, and shows the proper fixes for many of them.
Length
1 day. Each day is 4 hours long including a 15 minute break.Class Size
Our classes are priced for small and large classes. We offer classes starting at only five students, up to 100 students. We recognize that each company has specific needs and budgets.
For pricing, fill out our contact us form and you'll receive an automated reply with our current rates.
Target Audience
- You have been doing daily Go development for 3-6 months and want to master more advanced topics.
- You want to learn how to profile your Go code and improve performance.
Prerequisites
- Familiarity and comfort navigating and basic file manipulation at the command line.
- Familiarity and comfort with a modern code editor, including creating and modifying files and projects.
- You have 3 to 6 months of daily Go experience.
- You have at least 1 year of experience with other modern development languages such as Java, C#, Swift, JavaScript, Python, Rust, etc.
- Familiarity with basic programming concepts and structures such as variables, loops, conditionals, etc.
- Computers should be capable of modern software development, such as access to install and run binaries, install a code editor, etc. Full instructions referenced here: preparing your environment for Go development. It may be necessary for them to have root/admin access to their computer.
Recommended Preparation
- Install and configure an editor for Go.
- Have a functioning Go environment installed with Go 1.13 or later.
- Sign up for a Github account if you don't already have one.
- Install GraphViz (needed for generating Go profiles).
Suggested Followup Learning
Expected Outcomes
- Students will understand how to install and run the pprof tool.
- Students will understand how to configure their Go code to create and capture performance profiles.
- Students will understand how to read a Go profile, torch graph, and navigate other pprof generated output.
- Students will understand the Go test ecosystem, as well as how to configure and run their Go tests efficiently.
- Students will be able to identify common performance pitfalls and correct them in their Go code.
Course Details
Day One
Profiling Go Applications for Performance Optimization
Profiling is a critical aspect of performance tuning in software development. In this chapter, we dive deep into the various profiling tools that Go provides, focusing on how to identify performance bottlenecks and optimize code effectively. You will learn how to generate CPU, memory, block, mutex, and thread creation profiles, and how to use interactive tools like `pprof` to analyze these profiles. Additionally, the chapter covers advanced topics like generating profiles from live applications, using profiling in benchmarks, and visualizing performance data with tools such as flame graphs. By the end of this chapter, you'll have the knowledge to pinpoint inefficient code and make informed decisions on how to enhance the performance of your Go applications.
Optimizing Go Services for High Performance
In this chapter, we delve into the advanced techniques and best practices for optimizing Go services to achieve better performance and efficiency. While tools like `pprof` and benchmarks are essential, the real value comes from identifying and addressing common coding inefficiencies that impact runtime performance. This chapter equips you with the skills to fine-tune your Go code by spotting these pitfalls, leveraging compiler tricks, and minimizing resource usage without sacrificing code clarity.
Break
Tea/Coffee Break.
Tracing
The execution trace captures a wide range of execution events such as goroutine creation/blocking/unblocking, syscall enter/exit/block, GC-related events, changes of heap size, processor start/stop, etc. A precise nanosecond-precision timestamp and a stack trace is captured for most events. The generated trace can be interpreted using `go tool trace`. This chapter will walk through how to enable tracing, use the trace tool, and spot performance issues. Go ships with several profiling tools, such as CPU, memory, and block profilers. Additionally, they have GC and scheduler tracers and a heap dumper. While each of these tools provide answers to many questions, they do it by "aggregating" information in many cases.
Prerequisites
Benchmarking
Benchmarking is an essential tool in Go for evaluating the performance of your code. This chapter introduces you to the powerful tools Go provides for benchmarking and performance analysis, allowing you to measure the efficiency of your code with precision. You will learn how to establish baseline performance, write effective benchmarks, and compare results to see the impact of optimizations. This chapter also delves into common pitfalls in benchmarking and how to avoid them, ensuring that your performance tests yield reliable, consistent results. Finally, we will explore advanced topics such as tracking memory allocations, handling compiler optimizations, and using tools like `benchstat` to analyze and compare benchmark data. By the end of this chapter, you'll have a solid foundation for systematically improving the performance of your Go applications.