May 31, 2022 By IBM Instana Team 2 min read

Memory leaks are common in almost any language—including garbage-collected languages—and Go is no exception. A reference to an object (if not properly managed) may be left assigned, even if unused. This usually happens on an application-logic level but can also be an issue inside an imported package.

Unfortunately, it’s hard to detect and fix memory leaks in development or staging environments—both because the production environment has different and more complex behavior and because many memory leaks take hours or even days to manifest themselves.

How to find memory leaks in production

Golang has a powerful profiling toolset called pprof that includes a heap allocation profiler. The heap profiler gives you the size of the allocated heap and the number of objects per stack trace (i.e., the source code location where the memory was allocated). This is critical information but is not sufficient as a single profile. To detect if there is an actual leak over a period of time, you need to record and compare regular allocation profiles.

Some issues when using pprof against production environments include the following:

  • The profiler’s HTTP handler, which accepts profiling requests, must attach itself to the application’s HTTP server or have one running. This means you should take extra security measures to protect the listening port.
  • Locating and accessing the application node’s host to run the go tool pprof may be tricky in container environments like Kubernetes.
  • If the application has crashed or can’t respond to the pprof request, no profiling is possible.
  • Obtaining the historical stack trace view of heap allocations—a regular manual pprof execution—requires interactive result analysis and comparison.

Using IBM Instana for automatic memory leak detection and profiling

The IBM Instana platform automates the collection of heap allocation profiles, solving the above-mentioned issues. The IBM Instana Go Profiler, initialized in the application, continuously records and reports allocation profiles to the dashboard.

See the IBM Instana Profiling documentation for detailed setup instructions. After the application is restarted or deployed, the profiles will be available in the dashboard in a historically comparable form.

Similar profile history is automatically available for CPU usage, blocking calls and HTTP handlers. CPU, memory and GC metrics from Go runtime are also automatically available in the dashboard.

If you aren’t already an IBM Instana user, you can get started with a free two-week trial
Was this article helpful?
YesNo

More from IBM Instana

IBM Instana wins the Devies 2023 Award in the Developer Category in Observability and Monitoring

2 min read - We’re excited to announce that IBM Instana Observability has won the Devies 2023 Award in the Developer Category in Observability and Monitoring. Just a few weeks into the new year, congratulations are in order to the Instana team. The 11th Annual Devies are the definitive annual awards for the software industry, recognizing outstanding design, engineering and innovation in developer technology across 31 categories. This recognition is a testament to IBM's hard work and dedication to delivering exceptional products that meet…

How to use Smart Alerts on Custom Events to monitor business metrics in real-time

3 min read - Are you a business owner trying to monitor and alert on your business metrics? Are you trying to reduce the time it takes to detect revenue-impacting issues? IBM Instana™ website monitoring, also known as end-user or real-user monitoring, tracks metrics and events on your websites. Real-time information about HTTP calls, errors and other events are collected as they’re happening within your browsers. IBM Instana Custom Events identify activities that are happening more or less frequently than they should be. This…

Now available: The IBM Instana platform on-premises with the Red Hat OpenShift Platform

< 1 min read - Whether its Kubernetes or Red Hat® OpenShift®, the IBM® Instana® platform goes wherever you go. We’re excited to announce support for hosting Instana on-premises on Red Hat OpenShift. The Instana on-premises observability backend empowers system administrators with the complete suite of features available in the IBM Instana Observability platform while also maintaining full data custody and avoiding potentially expensive data transmission. The Instana platform already supports a seamless installation process in Kubernetes using helm. We can now offer a similar…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters