You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/04/12 04:27:08 UTC

[GitHub] [skywalking] nickwongwong commented on a change in pull request #6729: GlobalIdGenerator will produce a negative id when the time shift back

nickwongwong commented on a change in pull request #6729:
URL: https://github.com/apache/skywalking/pull/6729#discussion_r611319453



##########
File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
##########
@@ -73,9 +73,19 @@ private long timestamp() {
             long currentTimeMillis = System.currentTimeMillis();
 
             if (currentTimeMillis < lastTimestamp) {
+                long overTime = lastTimestamp - currentTimeMillis;
+                if (overTime <= 5) {
+                    try {
+                        Thread.sleep(overTime);

Review comment:
       ![image](https://user-images.githubusercontent.com/16626084/114339294-6908b280-9b87-11eb-98f0-d95c44c2e2f1.png)
   Change `overTime` to 1ms.
   Use `LockSupport.parkNanos` instead of `Thread.sleep`.
   ![image](https://user-images.githubusercontent.com/16626084/114339407-b08f3e80-9b87-11eb-9fef-1b6968ca9de8.png)
   
   Actually, the `NTP` time offset(time shift) is very small in Linux servers.
   `1ms` may cover most cases, while keeping good performance.
   ![image](https://user-images.githubusercontent.com/16626084/114340192-96566000-9b89-11eb-96cf-246cb04d1a46.png)
   
   If ok, I will modify this PR.




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org