Skip to content
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

enhancement: batch events out metric in Pipeline #8383

Merged
merged 2 commits into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ pub struct Pipeline {
#[derivative(Debug = "ignore")]
inlines: Vec<Box<dyn FunctionTransform>>,
enqueued: VecDeque<Event>,
events_outstanding: usize,
}

impl Pipeline {
fn try_flush(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), <Self as Sink<Event>>::Error>> {
// We batch the updates to "events out" for efficiency, and do it here because
// it gives us a chance to allow the natural batching of `Pipeline` to kick in.
if self.events_outstanding > 0 {
emit!(EventOut {
count: self.events_outstanding
});
self.events_outstanding = 0;
}

while let Some(event) = self.enqueued.pop_front() {
match self.inner.poll_ready(cx) {
Poll::Pending => {
Expand Down Expand Up @@ -79,7 +89,8 @@ impl Sink<Event> for Pipeline {
}

fn start_send(mut self: Pin<&mut Self>, item: Event) -> Result<(), Self::Error> {
emit!(EventOut { count: 1 });
self.events_outstanding += 1;

// Note how this gets **swapped** with `new_working_set` in the loop.
// At the end of the loop, it will only contain finalized events.
let mut working_set = vec![item];
Expand Down Expand Up @@ -142,6 +153,7 @@ impl Pipeline {
// We ensure the buffer is sufficient that it is unlikely to require reallocations.
// There is a possibility a component might blow this queue size.
enqueued: VecDeque::with_capacity(10),
events_outstanding: 0,
}
}
}
Expand Down