Memory leak in an infinite service

Sorry for the mistakes I’m making translate.google
I need to create a program that runs endlessly, it needs to query records from a postgres database and process this information.

I have a lot of data to process.

The problem is that it is consuming memory and does not release more, I tried everything I read several articles on good practices for database querying and processing with goruntines.

Has anyone ever had a similar problem? or know how I can know which part of the code is not releasing the memory correctly?

Thanks for the help!

If you don’t show us any code, it is impossible to help you.

Can you show us the relevant parts of your code that demonstrates the problem?

pprof with the -memprofile option could be a good start.
Example: go test -memprofile mem.prof -bench .
Go package reference : https://golang.org/pkg/runtime/pprof/
Relevant Go blog post: https://blog.golang.org/profiling-go-programs
Scroll down the blog entry to see this example:

$ go tool pprof havlak3 havlak3.mprof  
Adjusting heap profiles for 1-in-524288 sampling rate  
Welcome to pprof!  For help, type 'help'.  
(pprof) top5  
Total: 82.4 MB  
    56.3  68.4%  68.4%     56.3  68.4% main.FindLoops  
    17.6  21.3%  89.7%     17.6  21.3% main.(*CFG).CreateNode  
     8.0   9.7%  99.4%     25.6  31.0% main.NewBasicBlockEdge  
     0.5   0.6% 100.0%      0.5   0.6% itab  
     0.0   0.0% 100.0%      0.5   0.6% fmt.init  
(pprof)

See how main.FindLoops used 56.3MB memory

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.