diff --git a/CHANGES.md b/CHANGES.md index 2c3d381cf8062abb6804ff3cc5339e6cb9c81a0f..099fb3e84135eb04bf483e758a390fc13c884344 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,7 @@ Release Notes. #### Java Agent * Add `trace_segment_ref_limit_per_span` configuration mechanism to avoid OOM. - +* Improve `GlobalIdGenerator` performance. #### OAP-Backend * BugFix: filter invalid Envoy access logs whose socket address is empty. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java index 0adb77d3d34fd9bd7b4ffa4bfb23d95f0946e6c5..bfb38f7aa0ac6c87244ada5185452c2a559836fa 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java @@ -19,7 +19,6 @@ package org.apache.skywalking.apm.agent.core.context.ids; import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; import org.apache.skywalking.apm.util.StringUtil; @@ -57,8 +56,8 @@ public final class GlobalIdGenerator { private short threadSeq; // Just for considering time-shift-back only. - private long runRandomTimestamp; - private int lastRandomValue; + private long lastShiftTimestamp; + private int lastShiftValue; private IDContext(long lastTimestamp, short threadSeq) { this.lastTimestamp = lastTimestamp; @@ -74,11 +73,11 @@ public final class GlobalIdGenerator { if (currentTimeMillis < lastTimestamp) { // Just for considering time-shift-back by Ops or OS. @hanahmily 's suggestion. - if (runRandomTimestamp != currentTimeMillis) { - lastRandomValue = ThreadLocalRandom.current().nextInt(); - runRandomTimestamp = currentTimeMillis; + if (lastShiftTimestamp != currentTimeMillis) { + lastShiftValue++; + lastShiftTimestamp = currentTimeMillis; } - return lastRandomValue; + return lastShiftValue; } else { lastTimestamp = currentTimeMillis; return lastTimestamp;