-
Notifications
You must be signed in to change notification settings - Fork 93
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
ref(metrics): Use a priority queue for metrics aggregator #3845
Conversation
@@ -122,6 +122,7 @@ pest = "2.1.3" | |||
pest_derive = "2.1.0" | |||
pin-project-lite = "0.2.12" | |||
pretty-hex = "0.3.0" | |||
priority-queue = "2.0.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting crate, might actually be a good replacement for my homegrown priority map. But do we need it for the aggregator use case? IIUC the std binary heap should be good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need keyed access and priority separately. Keyed for the aggregation key, priority for the flush time.
977facc
to
f9878c6
Compare
Looked into not using a dependency for this but instead having a I'd just go with the dependency and revisit this again if performance is still not good enough or when we're looking into priority queue alternatives for the spooler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See question about change_priority_by
vs get_mut
.
break; | ||
} | ||
|
||
let (key, entry) = self.buckets.pop().expect("pop after peek"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awkward, right? For our own priority map I'm considering writing an interface that lets you do let value = queue.peek().remove()
instead of queue.pop()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace = entry.key().namespace().as_str(), | ||
); | ||
let mut error = None; | ||
let updated = self.buckets.change_priority_by(&key, |value| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we not use self.buckets.get_mut()
here? IIUC, the closure is only called if the element exists, and we don't actually update any priorities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_mut
only returns the key as mutable, but we need a mutable value which also causes this unfortunate error handling.
It's kinda double unfortunate API wise, because we never change the priority, maybe worth investigating wrapping the value itself in a RefCell
then we can use get()
although I am not sure if that makes it better ...
Uses a priority queue for the metrics aggregator:
#skip-changelog