Closed pracucci closed 1 month ago
pt2, "Do you see any issue" -- probably not. I currently take deliberate care within the client to not go through the end-user Request
path, to not have this secondary caching for the general consumer/producer. Of the 7 requests that use fetchMappedMetadata, 5 are admin requests, and the other two are. ListOffsets and OffsetForLeaderEpoch. These latter two are only used while consuming, and I have a fairly large chunk of code in consumer.go dedicated to issuing these requests directly (and handling the responses in a paranoid way). So, the change here to always pipe producer/consumer metadata responses through the separate fetchMappedMetadata cache will increase memory.
I'll look through the code change / callback more when I get time soon; the past two months have been busier than I was expecting, but getting through issues & PRs is actually at the top of the priority list at the moment.
Good enough, we'll see if somebody even notices a minor memory bump. +1!
Thanks for the review! Feel free to revert (or ping me) if anyone complain about it.
In Mimir, we have a process creating 1
Client
(settingMetadataMinAge
= MetadataMaxAge = 10s`) and then using it to do two things:ListOffsets
every 1sI noticed that such
Client
issues 2Metadata
requests everyMetadataMinAge
(remember that we setMetadataMaxAge = MetadataMinAge
).One request is due to the periodic Metadata refresh, and one is due to
ListOffsets
which needMetadata
as well.ListOffsets
request callsClient.fetchMappedMetadata()
which caches the metadata forMetadataMinAge
, so effectively leading to 2Metadata
requests everyMetadataMinAge
.In this PR I'm proposing to optimistically cache the mapped metadata when cluster metadata is periodically refreshed.
Notes
fetchMappedMetadata()
comment says "this is garbage heavy, so it is only used in one off requests in this package". Part of the the garbage is introduced by caching the mapped metadata, which is now done each time metadata is refreshed. Do you see any issue?storeCachedMappedMetadata()
, but I haven't come up with a better idea which either doesn't make code more complex or introduce more allocations. Thoughts?Metadata
requests dropped from 2 to 1 everyMetadataMinAge