-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: Go routine and writer memory not being released #32124
Comments
There is no
That sounds more-or-less as expected: search for
That sounds like a reasonable behavior for a buffered filesystem. |
None of the described behaviors seem at odds with the documented behavior of the Go runtime. Could you give some more detail about what other outcome you expected and why? |
you are correct, the current commit I had pushed was my attempt with bufio.Write(). I was stating that we had previously used os.Write().
I'll do more tests of the memory with GOGC, but I missed stating above that we tested with debug.FreeOSMemory. Here are some snapshots from Grafana with some of things you suggested I have tested this morning. Test 1: Current code base from Leaky-Parser Test 2: Adding debug.FreeOSMemory on L#98 and L#115 Test 3: Instead of using bufio.Writer, I switch to os.Write() on L#265 and os.Sync() instead of w.Flush() on L#271 Test 4: Using os.Write() from Test 3 with debug.FreeOSMemory similar to Test 2 What I was expecting to see was that memory will be reclaimed after the channels and files are closed especially after decryption, but not how it's hanging around after 10 minutes. |
On Darwin we call With that being said in Go 1.13 we use a Darwin-specific Also in Go 1.13, we scavenge memory much more aggressively (#30333), so you will no longer need to wait minutes for memory to start being returned to the OS. Please try running this with Go built at tip. I think this problem should be already solved for Go 1.13. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
What version of Go are you using ( go version )?
What did you do?
https://github.com/CyberNinja89/leaky-parser
This repository contains a small project that demonstrates a scenario where memory is not being released after worker threads finish performing reading and writing tasks. Explicit buffer flushes, os.sync(), file closures, and channel closures have been called, but memory is still being held onto.
What did you expect to see?
The memory usage upon leaving the scope of the function should return to the levels of memory usage before entering the function call.
What did you see instead?
Within a kubernetes environment, this application will consume a majority of the node's memory (8GB) according to Grafana. The application will continue to run at high memory levels (>2 GB) until it the finishes the function. At this point, memory usage will slowly climb down but after time it will stabilize and have released about 20-30%.
In a few tests with kubernetes, we have commented out the os.Write (tried bufio.Write too) in the writer channels. Memory usage held steadily below 200 MB, but at scale, memory being released afterwards was at most 50%.
Locally on Mac, the application memory according to the activity monitor never reached above 20MB, but the memory for cached files kept growing until it reached capacity of the macbook pro. After processing the files, the cached file memory stayed at those levels until application was terminated.
In each of tests we ran with a thousand workers(go routines) for reading and encrypt/decrypt
System details
Kubernetes
Local Machine
The text was updated successfully, but these errors were encountered: