https://play.golang.org/p/e22ufH-T2M1 This is my sample data structure. package main import ( type MicroChkpt struct { type CallChkpt struct { var CallChkptMap map[uint32]*CallChkpt func main() { So its a nested map structure, CallChkptMap->MicroChkptMap->MicroChkptInfoMap Its not happening till all entries are removed from the top level map( then only i see memory dipping), map has ongoing insert and delete operations and grows pretty big. Should i go to the nested maps first, set them to nil and then delete the entry from the top level map? |
I have my system up and running for let's say 10 hours or so where these operations on map ( continuous add/delete) keep happening. Memory keeps growing and goes very high.Eventually at end of test we clear all map entries, memory is reclaimed and is good.It's basically kind of load test.Appreciate your engagement.
On Mon, 27 Apr, 2020, 3:41 AM Ian Lance Taylor, <ia...@golang.org> wrote:
I have my system up and running for let's say 10 hours or so where these operations on map ( continuous add/delete) keep happening. Memory keeps growing and goes very high.Eventually at end of test we clear all map entries, memory is reclaimed and is good.It's basically kind of load test.Appreciate your engagement.
bigSlice := make([]int, 1000*1000)
subSlice := bigSlice[0:1:1]
bigSlice = nil
runtime.GC()
// At this point, bigSlice is still allocated! It cannot be freed by the GC (in the current implementation)
useTheSlice(subSlice)
Basically using the Top command at end of test.Let me give a quick summary of the scenario.Basically we have an application which keeps getting data on a TCP connection, we allocate a global slice to temporarily hold the data and then store in nested maps.For every TCP data transaction, we store the data in a global slice temporarily and then operate on the maps.For a certain amount of data, i know what should be the total allocation, but when i check using top command at end of test its almost always double or slightly more.if I call runtime.GC() on every tcp transaction, memory looks good and end of test it is as expected ( everything reclaimed)Is it because the system is heavily loaded ( per sec we may be getting huge no of transactions) so garbage collector cant keep track of the objects to be freed.As a test I even tried to block the delete operations on Map, just addition to maps on a smaller scale though, even then memory is almost double of what is expected.only solution is calling runtime.GC() on every tcp transaction, then everything is fine.I am really not sure whether the map deletions don't work properly or is it just the GC which is not able to work efficiently enough on its own.Calling GC so often is an overhead and would cause CPU spikes.
On Tue, Apr 28, 2020 at 3:21 AM Ian Lance Taylor <ia...@golang.org> wrote:
On Apr 28, 2020, at 3:18 PM, 'Kevin Chowski' via golang-nuts <golan...@googlegroups.com> wrote:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f4b8f164-085c-4d3e-8f51-c16138c3ac83%40googlegroups.com.
Basically using the Top command at end of test.
On Thu, May 7, 2020 at 11:57 AM Naveen Kak <navee...@gmail.com> wrote:
>
> Ian,
> Any thoughts on this? Appreciate a response.
I'm sorry, I'm not sure what you want a response on.
Using top is a fine way to see total memory usage of your application.
It's a terrible way to examine the Go garbage collector. Using
runtime.ReadMemStats will give you a better understanding of the
garbage collector.
Whether it makes sense to use sync.Pool depends on your application.
The sync.Pool documentation explains when it is useful.
Ian