-
Notifications
You must be signed in to change notification settings - Fork 603
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
Memory Leak? #407
Comments
Based on napkin calculations: 1024 (shards) * 10 (initialShardSize) * 1024 * 100 (MaxEntrySize) = 1GB Lines 434 to 454 in a2f05d7
How did you measure used memory?
|
Sorry, it was my mistake. The correct value should be 1GB.
What I’m confused about is that I initialized a 1GB cache, but it wasn’t actually used right away. Moreover, after the program started, the memory didn’t increase immediately. Instead, the cache only grew to 1GB as the number of processed HTTP requests increased. I measure used memory by continuous observation windows 11's Process Monitor Software working set memory, The working set refers to the physical memory usage, not the virtual memory usage. I understand that 1GB of virtual memory was allocated when initializing the cache, but during the actual HTTP request processing, this cache wasn’t immediately utilized. Why, then, does the physical memory usage rapidly and continuously increase to 1GB? Within a few seconds, the physical memory usage increases. There is my stress test script:
Thank you for your patient reply. |
That's good to hear as that's something I got with my napkin math.
bigcache eagerly allocate memory it estimates to be used based on passed config. This is done to minimise new allocations later.
That's great question but I'm afraid beyond my knowledge limits :( I believe that as a program you have no idea what type of memory you get from OS and the OS decided about virtual/physical allocations. 1GB is not much theses days so if it fits your RAM then there is no reason to allocate it somewhere else. You can try filling your ram and then running code. You need to keep in mind that Go manages memory for you, so there is a chance that GC or runtime "touches" allocated slices preventing them from swaping 🤷 |
Question:
Why does the memory usage of BigCache keep growing in the following code? The function handling HTTP requests does not involve any BigCache read or write operations.
Every time this program runs, the memory usage quickly increases to around 10GB.
Go Version:1.23
Go Mod:
My Code:
The text was updated successfully, but these errors were encountered: