This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new c7916d9 improve ContextManager.stopSpan performance: call ThreadLocal
only once (#3068)
c7916d9 is described below
commit c7916d9f2715ff9d3c415f86418d8f81c97a21e7
Author: qxo <[email protected]>
AuthorDate: Thu Jul 18 00:17:04 2019 +0800
improve ContextManager.stopSpan performance: call ThreadLocal only once
(#3068)
* improve ContextManager.stopSpan and awaitFinishAsync performance: call
ThreadLocal only once
For the [JMH benchmark
test](https://gitlab.com/qxo1/Common-JMH-benchmark/-/jobs/251025992) :
On gitlab CI(java 8): call ThreadLocal once vs twice fast over 10%
My T480 java 8 : fast over 40%; java 11: fast over 50%;
[The JMH benchmark code
](https://github.com/qxo/Common-JMH-benchmark/blob/master/src/main/java/test/ThreadLocalGetXTimeBenchmark.java)
* Update
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
Co-Authored-By: kezhenxu94 <[email protected]>
* Update
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
Co-Authored-By: kezhenxu94 <[email protected]>
* Update
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
Co-Authored-By: 吴晟 Wu Sheng <[email protected]>
---
.../apm/agent/core/context/ContextManager.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
index 9c3f48d..90ffdb1 100644
---
a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
+++
b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java
@@ -150,11 +150,12 @@ public class ContextManager implements BootService {
}
public static AbstractTracerContext awaitFinishAsync(AbstractSpan span) {
- AbstractSpan activeSpan = activeSpan();
+ final AbstractTracerContext context = get();
+ AbstractSpan activeSpan = context.activeSpan();
if (span != activeSpan) {
throw new RuntimeException("Span is not the active in current
context.");
}
- return get().awaitFinishAsync();
+ return context.awaitFinishAsync();
}
/**
@@ -165,12 +166,22 @@ public class ContextManager implements BootService {
return get().activeSpan();
}
+ /**
+ * Recommend use ContextManager::stopSpan(AbstractSpan span), because in
that way,
+ * the TracingContext core could verify this span is the active one, in
order to avoid stop unexpected span.
+ * If the current span is hard to get or only could get by low-performance
way, this stop way is still acceptable.
+ */
public static void stopSpan() {
- stopSpan(activeSpan());
+ final AbstractTracerContext context = get();
+ stopSpan(context.activeSpan(),context);
}
public static void stopSpan(AbstractSpan span) {
- if (get().stopSpan(span)) {
+ stopSpan(span, get());
+ }
+
+ private static void stopSpan(AbstractSpan span, final
AbstractTracerContext context) {
+ if (context.stopSpan(span)) {
CONTEXT.remove();
RUNTIME_CONTEXT.remove();
}