-
Notifications
You must be signed in to change notification settings - Fork 107
account for the cap() of byte slices in ccache #963
Conversation
e1d94cd
to
5dc1a82
Compare
we should either:
we currently do 1. I think we can look into optimizing ccache overhead and see if we can deduce some kind of heuristic or formula to estimate "true" memory usage given a number of chunks and metrics cached. |
@replay let me know what you think of the above. if you agree, is there anything in this PR i should still look at? because i didn't look in detail at the code yet. |
The idea of this PR was simply that we wanted to know if the allocated byte slices that are used to keep the iterators are sometimes bigger than necessary. By comparing the |
knowing as part of a debugging / development process or need to know constantly for running production services? we've made the mistake in the past of adding too much runtime instrumentation for things that we only need when troubleshooting a performance problem, those are well served by just some temporary instrumentation that doesn't need to be merged. (e.g. index duration metrics were removed for this reason) |
That's a question which is hard to answer, because if there is an issue where the allocated bytes slices are larger then necessary then we don't know exactly in which situations this would/wouldn't happen. F.e. a Sarama update could probably introduce an issue like that. But I guess for a start it would already be useful to just deploy that anywhere where MT is in production use in order to then be able to compare the |
I believe I added them originally, then deleted them later when i discovered they were slowing down ingestion. couldn't find the PR right now, but it's out there somewhere. FWIW, AFAIK the go runtime doubles capacity to accommodate a len up to 1024 or so, then increments in 25% steps from there, but of course that assumes no reusing of previously allocated slices. Are we observing any concrete problems that we think this patch will help us with, and if so can you explain the actual problem? Otherwise I believe you can get the answers you need via
|
The problem we're observing is that MT appears to be consuming more memory than expected, so one theory that we came up with while you were on vacation was that maybe the byte slices used to store the iterators have a capacity that's larger than necessary. This PR was supposed to make it easy to verify if this is true or not. |
we should make the accounting accurate as brought up in #942 |
@replay @woodsaj FYI some followup: I dug a bit in the code, it's not that hard to follow to doublecheck i applied the following patch:
and when i request data, the output looks like so:
you can see that the slice coming from the framer has a larger capacity, probably because it contains much more stuff because it holds a frame, but the slice we get holding our chunk is sized just right for our chunk. So :
What is interesting however, is to reduce allocations (but not memory in use), is perhaps we can recycle slices. I've brought this up on their list: https://groups.google.com/forum/#!topic/gocql/ng0d9ZyGwSU |
Prior to this change we were only counting the number of bytes that the actual data occupied. However, there is a lot of overhead in our cache system that also needs to be tracked. We were seeing large differences in the total cache size used and and live heap allocations. These changes attempt to track most of the accounting overhead. The numbers used to track overhead are estimates based on data type sizes. * Added stats for Flat Acccounting, the LRU, and Chunks * Added benchmark for LRU allocations Resolves: #1086 See also: #963
We want to know how much memory MT allocates for the cache, so we also need to keep track of the
cap()
of the data in the cache, instead of only tackinglen()
.To get a really clear picture of how much memory is used for the chunk cache we'll need to add more metrics. Every time a chunk is added to the cache, there's some overhead for it in the data structure of the chunk cache itself, and also in the accounting for it. I think we should add two more metrics, one is keeping track of the overhead of the chunk cache data structure and another one keeps track of the overhead for the accounting itself.