Repository navigation
Avoid quadratic Vec::remove(0) when splitting batches - #372
Merged
Merged
Conversation
When a request doesn't fit in the remainder of the current batch,
BatchSplittable::split moved the first N spans (metrics, log records)
into the new ScopeSpans one at a time with Vec::remove(0), shifting the
rest of the vector on every call: O(N * len) memmove per split. With
1000-span requests and the default 8192 batch size this was 13% of SUT
CPU in an OTLP->OTLP saturation profile (31% with the blackhole
exporter), almost all of it in memmove.
Move the items with a single drain(..n) instead.
Benchmark (rotel-bench, Intel N95, SUT pinned to 1 core, closed loop,
1000 items/request, 5 runs per variant, ABBA, mean ± stddev):
traces OTLP gRPC -> OTLP gRPC (gzip) 277.5k±0.4k -> 307.4k±0.6k spans/s (+10.8%)
CPU/span -9.9%, p50 -10%, p99 -12%
traces, realistic span shape 156.1k±5.6k -> 167.4k±3.0k spans/s (+7.3%)
logs OTLP gRPC -> OTLP gRPC 287.2k±0.5k -> 310.8k±0.5k logs/s (+8.2%)
metrics (150 metrics x 7 points/req) unchanged (+0.3%)
traces -> blackhole, on top of the TCP_NODELAY change:
902.3k±1.5k -> 1294.3k±2.3k spans/s (+43%)
CPU/span -31%, p50 -31%, p99 -32%
Fixed-rate scenarios with 100-item requests: CPU/item -0.3..-1.2%,
latency and RSS unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
When a request doesn't fit in the remainder of the current batch, BatchSplittable::split moved the first N spans (metrics, log records) into the new ScopeSpans one at a time with Vec::remove(0), shifting the rest of the vector on every call: O(N * len) memmove per split. With 1000-span requests and the default 8192 batch size this was 13% of SUT CPU in an OTLP->OTLP saturation profile (31% with the blackhole exporter), almost all of it in memmove.
Move the items with a single drain(..n) instead.
Benchmark (rotel-bench, Intel N95, SUT pinned to 1 core, closed loop, 1000 items/request, 5 runs per variant, ABBA, mean ± stddev):
traces OTLP gRPC -> OTLP gRPC (gzip) 277.5k±0.4k -> 307.4k±0.6k spans/s (+10.8%)
CPU/span -9.9%, p50 -10%, p99 -12%
traces, realistic span shape 156.1k±5.6k -> 167.4k±3.0k spans/s (+7.3%)
logs OTLP gRPC -> OTLP gRPC 287.2k±0.5k -> 310.8k±0.5k logs/s (+8.2%)
metrics (150 metrics x 7 points/req) unchanged (+0.3%)
traces -> blackhole, on top of the TCP_NODELAY change:
902.3k±1.5k -> 1294.3k±2.3k spans/s (+43%)
CPU/span -31%, p50 -31%, p99 -32%
Fixed-rate scenarios with 100-item requests: CPU/item -0.3..-1.2%,
latency and RSS unchanged.