zipkin-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-zipkin-brave] devinsba commented on a change in pull request #908: Fixes some edge cases around sampler resetting
Date Mon, 13 May 2019 17:50:55 GMT
devinsba commented on a change in pull request #908: Fixes some edge cases around sampler resetting
URL: https://github.com/apache/incubator-zipkin-brave/pull/908#discussion_r283461739
 
 

 ##########
 File path: brave/src/main/java/brave/sampler/RateLimitingSampler.java
 ##########
 @@ -55,14 +55,17 @@ public static Sampler create(int tracesPerSecond) {
     long updateAt = nextReset.get();
 
     long nanosUntilReset = -(now - updateAt); // because nanoTime can be negative
-    boolean shouldReset = nanosUntilReset <= 0;
-    if (shouldReset) {
-      if (nextReset.compareAndSet(updateAt, updateAt + NANOS_PER_SECOND)) {
-        usage.set(0);
-      }
+    if (nanosUntilReset <= 0) {
+      // Attempt to move into the next sampling interval.
+      // nanosUntilReset is now invalid regardless of race winner, so we can't sample based
on it.
+      if (nextReset.compareAndSet(updateAt, updateAt + NANOS_PER_SECOND)) usage.set(0);
 
 Review comment:
   The recursion below should also solve that, but having not seen that problem (`updateAt`
being more than a second in the past) in my first reading, the recursion is now screaming
stack overflow to me so I think that needs to be addressed

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@zipkin.apache.org
For additional commands, e-mail: dev-help@zipkin.apache.org


Mime
View raw message