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
Welcome To Go Training: Meet Your Instructor And Get Started
In this introductory module, you’ll be introduced to your instructor and the course materials that will guide you through the Go training. You'll find contact details for your instructor, access to the course content, and instructions on setting up your development environment. We'll ensure you’re prepared for a smooth learning experience, with access to all course updates and materials for life. Additionally, you’ll learn how to access further resources and support. Before diving in, we encourage everyone to introduce themselves and share their goals for the course.
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.
Key Takeaways
- Learn to identify and remove unnecessary memory allocations.
- Understand how to buffer readers and writers to optimize I/O performance.
- Use flame graphs and other profiling tools to eliminate redundant operations.
- Recognize when and where to optimize without introducing unnecessary complexity.
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.
Beyond The Classroom: Go Resources And Continued Learning
This chapter provides valuable resources to help you continue your journey with Go after the course. It includes links to official documentation, community support channels, recommended books, and video tutorials to deepen your understanding. Additionally, you’ll find ways to stay engaged with the Go developer community through Slack, mailing lists, and social media groups. We also introduce the Gopher Guides team, provide contact information for further training or consulting services, and share how to reach your instructors. Lastly, we encourage you to provide feedback to help us improve our offerings.
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.