Repository navigation
Add batch_observe methods to Histogram and Summary - #1228
Open
MahmoudAshraf97 wants to merge 1 commit into
Open
MahmoudAshraf97 wants to merge 1 commit into
MahmoudAshraf97 wants to merge 1 commit into
Conversation
Signed-off-by: MahmoudAshraf97 <hassouna97.ma@gmail.com>
MahmoudAshraf97
force-pushed
the
batched_observe
branch
from
October 16, 2026 08:55
dddd69e to
9c7fd6c
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds batch methods for observing a list of values that become available at once.
Motivation
The use case for this is in high-throughput ML inference systems where some metrics are calculated for the whole batch at once such as queue time spent per element, we usually looped over the elements and used
Histogram.observe, but each call involved python loop overhead and acquired two locks per callSpeedup
Python 3.12.3, x86_64 (AMD EPYC 9334), default buckets, best of 5. Loop = n calls to
observe().Single process (MutexValue)
Multiprocess mode (MultiProcessValue, mmap write per inc)
It might seem that despite the large speedup, it is still in order of microseconds, but in our use case, these microseconds block the asyncio event loop for hundreds of other tasks, and these batched methods increased the total system throughput by 2% just by improving observability tools, which is meaningful given the current GPU prices
I'm also open to extend the regular
observemethods to accept lists or sequences, but this is left for the maintainers to decideTIA