rajeshkumarchandolu opened a new pull request, #12162: URL: https://github.com/apache/ozone/pull/12162
## What changes were proposed in this pull request? `TraceAllMethod` is the `InvocationHandler` behind the tracing proxies created by `TracingUtil`: the OM client in `RpcClient`, and the SCM block location, container location, security and secret-key clients. When tracing is enabled, every call on those clients goes through it. This PR reduces its per-call and proxy-creation cost: 1. **No span under an unsampled parent.** If the current span is valid but not sampled, the delegate is called directly. A child of an unsampled parent would be dropped by the sampler anyway (`SpanSampler` already drops it), so creating the span was pure overhead. Calls without a parent still create a root span and leave the decision to the sampler. 2. **Method info cached per delegate class.** Whether a method is skipped, its annotated span kind and its span name are computed once per delegate class, when its first proxy is created, and kept in a `ClassValue` so they are released with the class. Previously every proxy scanned `getMethods()` in its constructor, and every call cloned the parameter types and scanned the matching methods linearly. 3. **Span names precomputed** instead of concatenated on every call. 4. **Consistent span names.** Spans are now always named `<DelegateClass>.<method>`. Previously `createClientProxy`/`createInternalProxy` used the interface name while `createProxy` used the delegate class name, and the SCM security client already used its class name. Anonymous, lambda and JDK proxy delegates fall back to the name of the interface declaring the method. The `TraceAllMethod` constructor no longer takes a name; the public `TracingUtil` methods are unchanged. Behavior changes: - Client proxy span names change, for example `OzoneManagerProtocol.getKeyInfo` → `OzoneManagerProtocolClientSideTranslatorPB.getKeyInfo` and `ScmBlockLocationProtocol.allocateBlock` → `ScmBlockLocationProtocolClientSideTranslatorPB.allocateBlock`. Existing `ozone.tracing.span.sampling` entries using the old names need updating. - With plain ratio sampling (no `ozone.tracing.span.sampling`), children of an unsampled parent are no longer recorded even if this process's ratio is higher than the caller's. This matches `SpanSampler` and avoids orphaned spans. - `toString`, `hashCode` and `equals` are never traced, even when the delegate overrides them. JMH results (JDK 17, 2 forks, 5×1 s warm-up, 5×1 s measurement, `-prof gc`); JDK 25 shows the same trend: | Call path | Before | After | Allocation per call | |---|---|---|---| | Direct call, no proxy (baseline) | 0.4 ns | 0.4 ns | 0 B | | Proxy, `@SkipTracing` method | 11.4 ns | 5.4 ns | 16 → 0 B | | Traced, inside an unsampled parent | 44.8 ns | 6.1 ns | 280 → 0 B | | Traced, new trace, not sampled | 60.0 ns | 54.0 ns | 384 → 304 B | | Traced, inside a sampled parent | 140.2 ns | 139.4 ns | 536 → 456 B | | Traced, new trace, sampled | 164.9 ns | 152.2 ns | 608 → 528 B | | Building a new proxy | 387.9 ns | 22.3 ns | 2,496 → 112 B | The remaining cost of a traced call is OpenTelemetry span creation. The benchmark is not part of this PR, to avoid adding the JMH dependency. ## What is the link to the Apache JIRA https://issues.apache.org/jira/browse/HDDS-17924 ## How was this patch tested? - New tests in `TestTraceAllMethod`: unsampled parent, sampled parent, repeated calls through the same `Method`, per-proxy span kind with the shared class cache, and anonymous-delegate naming. - Span-name assertions updated in `TestTraceAllMethod` and `TestTracingAnnotations`. - All 84 tests in `org.apache.hadoop.hdds.tracing` pass; checkstyle and PMD pass for `hdds-common`. - JMH microbenchmark on JDK 17 and JDK 25 (results above). -- 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]
