Production environments are different from development and staging. Whether optimizing application performance or trying to find a problem root cause, it is often necessary to use Go’s profiling tools in production.
Obviously, before doing anything in production, especially for performance optimizations, it makes sense to try to simulate production load and generate, for example, CPU or memory profiles with the built-in profilers using
go tool pprof.
Using built-in profilers
To profile remote applications,
go tool pprof accepts URLs, e.g.:
go tool pprof http://localhost:6060/debug/pprof/profile
The endpoint should be initialized on the application by importing the pprof http handler package:
import _ "net/http/pprof"
Also, the application should have a listening HTTP server, e.g.:
It’s important to ensure that this endpoint is not accessible to the outside world; for example, by only allowing access from internal addresses.
The next step would be to regularly request profiles from the application and track performance regression at the function call level or identifying the root cause of a performance problem.
Using Instana AutoProfile™ for Go
Instana’s AutoProfile takes production profiling to the next level. It continuously collects and reports profiles, including:
- CPU usage
- Memory allocations
- Blocking calls
These profiles, along with application and runtime metrics, are includes in Instana’s Unbounded Analytics Engine, where they can be viewed and compared. Analyzing performance differences at the function call level over time is critical for performance optimizations and problem root cause identification.
It takes only a few minutes to get AutoProfile set up and running. Sing up for a free two week trial, then install the Go Agent and enable profiling.
See the documentation for detailed setup instructions.