diff options
author | Diego <diegolparra@gmail.com> | 2014-12-03 23:44:38 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-12-03 23:44:38 -0300 |
commit | 42cd9db5615709365b687751223c72573e892429 (patch) | |
tree | 043d42690e7f186f842148088c4e52d5328a9d35 /kamon-core/src | |
parent | 3b063022d5c18418f9da82482311c67d486727d4 (diff) | |
download | Kamon-42cd9db5615709365b687751223c72573e892429.tar.gz Kamon-42cd9db5615709365b687751223c72573e892429.tar.bz2 Kamon-42cd9db5615709365b687751223c72573e892429.zip |
= core: use Sequencer instead of AtomicLong
Diffstat (limited to 'kamon-core/src')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 7 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/util/Sequencer.scala | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index 650592a5..5e6bef89 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -3,6 +3,7 @@ package kamon.trace import java.util.concurrent.atomic.AtomicLong import kamon.NanoInterval +import kamon.util.Sequencer import scala.concurrent.forkjoin.ThreadLocalRandom trait Sampler { @@ -31,9 +32,9 @@ class RandomSampler(chance: Int) extends Sampler { class OrderedSampler(interval: Int) extends Sampler { require(interval > 0, "kamon.trace.ordered-sampler.interval cannot be <= 0") - private val counter = new AtomicLong(0L) - def shouldTrace: Boolean = counter.incrementAndGet() % interval == 0 - // TODO: find a more efficient way to do this, protect from long overflow. + private val sequencer = Sequencer() + + def shouldTrace: Boolean = sequencer.next() % interval == 0 def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } diff --git a/kamon-core/src/main/scala/kamon/util/Sequencer.scala b/kamon-core/src/main/scala/kamon/util/Sequencer.scala index 8901ba81..f368e54f 100644 --- a/kamon-core/src/main/scala/kamon/util/Sequencer.scala +++ b/kamon-core/src/main/scala/kamon/util/Sequencer.scala @@ -18,7 +18,7 @@ package kamon.util /** * This class implements an extremely efficient, thread-safe way to generate a - * simple incrementing sequence of Longs with a simple Long overflow protection. + * incrementing sequence of Longs with a simple Long overflow protection. */ class Sequencer { private val CloseToOverflow = Long.MaxValue - 1000000000 |