-
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
http server and ioutil.readfile leaks memory #41818
Comments
Can you please update your example with correct error handling; ie. don’t log the error the continue to use b, which is in an unknown state, then confirm if the issue still occurs. Thank you. |
issue remains - no errors |
Thank you for updating your example. Can you please run your test with this environment variable set and paste the response, |
@blinkinglight could you also explain why you feel the server should use 100mb of memory, based on the inputs you explained, 4mb file, 1000 concurrent requests, the memory used of 4mb * 1000 is closer to the 3.3gb you reported. |
the problem is that then requests finishes, process doesnt release memory and after second benchmark process grow to 6gb of memory. |
|
Sadly the output is messed up because you used Can you please do this again using |
|
Thank you. It looks like to service 1000 concurrent 4mb responses memory usage is in excess of 2gb. If you leave the process for a few minutes the scavenger should run. When the Go scavenger finds free pages of memory it will ask the operating system via the madvise(2) syscall with the argument Furthermore, Linux's MADV_FREE is known to not actually modify any RSS counters until pages are purged due to memory pressure. As an alternative we can use Lastly, please remember that RSS is not a measure of how much memory is a program using, it is the resident segment size--the current amount of memory in core for the process. Many things influence the value reported in RSS including the availability of swap and how much of the process may be swapped, The amount of memory that the runtime has released to the operating system is recorded in the |
GODEBUG=madvdontneed=1 with debug.FreeOSMemory - solved the problem, after few seconds process stays ad 120mb ram |
Thank you, would you close this issue if you are satisfied. |
just one more question, can i set that go debug variable in code? not from env? |
no, it is not accessible from the |
ok. thank you. |
That's #40870, which is about to be declined. But you can write a program or shell script that sets the env var and then starts your app. |
Change https://golang.org/cl/267100 mentions this issue: |
In Go 1.12, we changed the runtime to use MADV_FREE when available on Linux (falling back to MADV_DONTNEED) in CL 135395 to address issue #23687. While MADV_FREE is somewhat faster than MADV_DONTNEED, it doesn't affect many of the statistics that MADV_DONTNEED does until the memory is actually reclaimed under OS memory pressure. This generally leads to poor user experience, like confusing stats in top and other monitoring tools; and bad integration with management systems that respond to memory usage. We've seen numerous issues about this user experience, including #41818, #39295, #37585, #33376, and #30904, many questions on Go mailing lists, and requests for mechanisms to change this behavior at run-time, such as #40870. There are also issues that may be a result of this, but root-causing it can be difficult, such as #41444 and #39174. And there's some evidence it may even be incompatible with Android's process management in #37569. This CL changes the default to prefer MADV_DONTNEED over MADV_FREE, to favor user-friendliness and minimal surprise over performance. I think it's become clear that Linux's implementation of MADV_FREE ultimately doesn't meet our needs. We've also made many improvements to the scavenger since Go 1.12. In particular, it is now far more prompt and it is self-paced, so it will simply trickle memory back to the system a little more slowly with this change. This can still be overridden by setting GODEBUG=madvdontneed=0. Fixes #42330 (meta-issue). Fixes #41818, #39295, #37585, #33376, #30904 (many of which were already closed as "working as intended"). Change-Id: Ib6aa7f2dc8419b32516cc5a5fc402faf576c92e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/267100 Trust: Austin Clements <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
dd if=/dev/null of=file.ts bs=4M count=1
ab -n 1000 -c 1000 http://localhost:10001/
What did you expect to see?
max 100Mb memory usage and no errors
What did you see instead?
3.3gb memory usage and no errors. debug.FreeOSMemory and runtime.GC doesnt helps
The text was updated successfully, but these errors were encountered: