Go's sendfile functionality impacted by middleware change
A recent middleware change in a small file-serving service using Go caused the CPU to double and throughput to roughly halve. The issue was traced back to a single line of code that wrapped a *os.File in a logging reader, disabling sendfile(2) functionality. This change impacted performance on a Linux 6.6 / Ubuntu 24.04 system with Go 1.22.12.
Key points
- The change involved wrapping a *os.File in a logging reader, which disabled sendfile(2) functionality.
- The impact was significant, with CPU doubling and throughput roughly halving.
- The issue was identified on a Linux 6.6 / Ubuntu 24.04 system with Go 1.22.12.
- Sendfile(2) is a kernel-level function that collapses two copies of data into one in-kernel transfer.
- The change highlights the importance of understanding the fast path in Go and how to maintain it for optimal performance.
- The issue has been documented in a blog post by a developer, providing insight into the problem and its solution.
Go's sendfile functionality impacted by middleware change
A recent middleware change in a small file-serving service using Go caused significant performance issues. The CPU doubled, and throughput roughly halved, leading to a thorough investigation of the cause.
The issue
The issue was traced back to a single line of code that wrapped a *os.File in a logging reader. This seemingly innocuous change had a profound impact on performance, disabling the sendfile(2) functionality.
Understanding sendfile(2)
Sendfile(2) is a kernel-level function that collapses two copies of data into one in-kernel transfer. This reduces the overhead associated with reading and writing data, making it an essential component of high-performance systems.
The impact
The change had a significant impact on the system, with CPU usage doubling and throughput roughly halving. This highlights the importance of understanding the fast path in Go and how to maintain it for optimal performance.
Conclusion
The issue has been documented in a blog post by a developer, providing insight into the problem and its solution. This serves as a reminder of the importance of careful coding and attention to detail when working with high-performance systems.
Tags
- go
- sendfile
- performance
- middleware
- linux
- ubuntu
- wsl2
Sources
The WireByte editorial team synthesises technology news from multiple primary sources, verifies the facts, and links every source. Articles are produced with AI assistance and reviewed under our editorial policy.