app4

command module
v0.0.0-...-cf9859a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

app4

A sample app in golang for identifying and fixing memory leaks in a golang application using pprof. A common pattern in memory usage that indicates a memory leak in an application is the "Sawtooth Pattern." This pattern is observed in memory usage graphs over time. Here's how it typically looks and what it signifies:

  • Rising Peaks: The memory usage increases steadily over time, indicating that the application is allocating more memory.
  • Sharp Drops: These occur when the garbage collector (GC) runs, freeing up some of the allocated memory. However, not all memory is reclaimed.
  • Higher Baselines Over Time: After each GC cycle, the baseline level of memory usage increases. This means that with each garbage collection, less memory is being freed, suggesting that some objects are not being released for GC.

Sawtooth Pattern

In our sample application /user is an endpoint with memory leakage. The server stores data for each user in the UserCache. On every request to /user, new user data is created and added to the cache. However, there's no code to remove old user data from the cache.

Run following command to generate memory profile

go test -run=XXX -memprofile memory.prof -bench .

And then to analyse the memory profile run

go tool pprof -http=0.0.0.0:8888 memory.prof

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL