Go, don't collect my garbage

Vlad Krasnov
7 min readintermediate
--
View Original

Overview

The article discusses performance benchmarking of Golang on a many-core machine, focusing on the impact of garbage collection on performance. It highlights the importance of tuning the GOGC variable to optimize performance in scenarios with high allocation rates and many goroutines.

What You'll Learn

1

How to benchmark Golang performance on many-core machines

2

Why tuning the GOGC variable can enhance performance in Go applications

3

When to disable garbage collection for short-lived data benchmarks

Prerequisites & Requirements

  • Understanding of Golang and its concurrency model
  • Familiarity with Go profiling tools like pprof(optional)

Key Questions Answered

How does garbage collection affect performance in Golang benchmarks?
Garbage collection significantly impacts performance, especially when generating large amounts of short-lived data. The article shows that with GOGC disabled, performance improved dramatically, achieving 413740.30 operations per second compared to lower rates with GC enabled. Frequent GC cycles can lead to performance degradation, as seen in the benchmarks.
What is the optimal GOGC setting for maximizing performance on a 24-core machine?
The optimal GOGC setting identified in the benchmarks is 11300, which resulted in 691054 signatures per second. This setting allows for less frequent garbage collection, improving throughput significantly when running on many cores.
What performance metrics were observed when benchmarking ECDSA P256 Sign?
The benchmarks showed varying performance metrics based on the number of goroutines. For example, with 1 goroutine, the performance was 30618.50 operations per second, while using 48 goroutines resulted in 78940.67 operations per second, peaking at 274622 operations per second with 17 goroutines.

Key Statistics & Figures

ECDSA-P256 Sign performance with 1 goroutine
30618.50 op/s
Measured during initial benchmarking on a single goroutine.
ECDSA-P256 Sign performance with 48 goroutines
78940.67 op/s
Observed during benchmarking with maximum goroutines.
Peak performance with 17 goroutines
274622 op/s
Identified as the optimal number of goroutines for this benchmark.
Performance with GOGC disabled
413740.30 op/s
Demonstrated the impact of disabling garbage collection.
Optimal GOGC setting
11300
Resulted in 691054 signatures per second during testing.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Golang
Used for performance benchmarking and garbage collection analysis.
Tools
Pprof
Profiling tool used to analyze performance bottlenecks in Go applications.

Key Actionable Insights

1
Consider disabling garbage collection for benchmarks that generate a high volume of short-lived data to achieve optimal performance.
In scenarios where the application generates temporary data that is quickly discarded, disabling GC can lead to significant performance gains, as demonstrated in the article.
2
Experiment with the GOGC variable to find the best setting for your specific workload.
The article illustrates how tuning GOGC from its default value can lead to substantial performance improvements, making it crucial for developers to test different configurations.
3
Utilize profiling tools like pprof to identify bottlenecks in Go applications.
Profiling can reveal how much time is spent on garbage collection and other operations, enabling developers to make informed decisions about performance optimizations.

Common Pitfalls

1
Over-reliance on default garbage collection settings can lead to suboptimal performance.
Many developers may not realize the significant impact that tuning the GOGC variable can have, especially in high-throughput scenarios. Testing different settings is essential to find the optimal configuration.
2
Assuming that more goroutines always lead to better performance.
The article demonstrates that performance can actually degrade after a certain number of goroutines due to increased garbage collection overhead, highlighting the importance of profiling and testing.

Related Concepts

Garbage Collection In Programming Languages
Concurrency In Golang
Performance Optimization Techniques