yandrey321 opened a new pull request, #12117:
URL: https://github.com/apache/ozone/pull/12117
## What changes were proposed in this pull request?
**Problem**
`TracingUtil.importAndCreateSpan` runs for every traced request on OM, SCM
and datanodes, and for each `OzoneManagerDoubleBuffer` child span. Each call
creates a new `TextExtractor`, which allocates a `HashMap` and parses the
carrier with `split(";")` plus a `split("=")` per entry. The W3C propagator
then reads only `traceparent` and `tracestate` from it.
In a `freon ockg` profile with tracing on (sampler ratio 1.0),
`importAndCreateSpan` was the largest server-side tracing frame: 0.7–1.3% of
CPU and 1.5–4% of allocations. Carrier parsing accounted for about 40% of that
frame's CPU on the OM leader.
**Implementation idea**
- `TextExtractor` no longer holds state. `get(carrier, key)` locates the key
in the carrier with `indexOf` and allocates only the returned value.
- `keys(carrier)` builds a `LinkedHashSet` only when called.
`W3CTraceContextPropagator` never calls it.
- `importAndCreateSpan` uses a shared `TextExtractor.INSTANCE` instead of
`new TextExtractor()` on every call.
- **Same parsing rules as the old code.** An entry counts only if it has
exactly one `=` after trailing `=` characters are dropped, as `String.split`
drops trailing empty strings. Keys and values are trimmed, and the last
duplicate wins. Simplifying these rules was rejected because it would change
results for malformed carriers.
- **A hand-written scan, not a regex or a cached map.** The carrier holds
one or two entries, so a linear scan per lookup is cheaper than building any
structure.
Co-authored-by: Claude Opus 5.5 <[email protected]>
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-17881
## How was this patch tested?
Unit tests
- **Micro-benchmark, not committed:** JDK 21, a real `traceparent` carrier,
one lookup each for `traceparent` and `tracestate` as the propagator does:
| Variant | Time per carrier | Allocation per carrier |
|---|---|---|
| before | 51 ns | 584 B |
| after | 27 ns | 96 B |
Allocation per carrier drops about 6x: the remaining 96 B is the returned
`traceparent` string. Time halves because the per-entry substring and array
copies are gone. At sampler ratio 1.0 this should cut tracing's share of server
allocation by about 1–2 percentage points and its CPU share by about 0.2–0.3
points. The W3C decode and `startSpan` costs are unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]