diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-04 01:51:58 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-04 01:51:58 -0300 |
commit | 3ae632dea4dd208ba22e56510c51ab222ea89148 (patch) | |
tree | 3de99b4d3686ee1ba938d1126937d09643419284 /kamon-core/src/main | |
parent | fc2333281acc028c79e1cfe00840666deea5a9d1 (diff) | |
download | Kamon-3ae632dea4dd208ba22e56510c51ab222ea89148.tar.gz Kamon-3ae632dea4dd208ba22e56510c51ab222ea89148.tar.bz2 Kamon-3ae632dea4dd208ba22e56510c51ab222ea89148.zip |
+ core: introduce the new kamon.metrics.default-collection-context-buffer-size setting
Diffstat (limited to 'kamon-core/src/main')
5 files changed, 23 insertions, 12 deletions
diff --git a/kamon-core/src/main/resources/reference.conf b/kamon-core/src/main/resources/reference.conf index b7f5c70e..3c8f3686 100644 --- a/kamon-core/src/main/resources/reference.conf +++ b/kamon-core/src/main/resources/reference.conf @@ -16,6 +16,16 @@ kamon { gauge-recording-interval = 100 milliseconds + # Default size for the LongBuffer that gets allocated for metrics collection and merge. The + # value should correspond to the highest number of different buckets with values that might + # exist in a single histogram during a metrics collection. The default value of 33792 is a + # very conservative value and its equal to the total number of buckets required to cover values + # from 1 nanosecond to 1 hour with 0.1% precision (3 significant value digits). That means + # that would need to have at least one measurement on every bucket of a single histogram to + # fully utilize this buffer, which is *really* unlikely to ever happen. Since the buffer should + # be allocated once and reused it shouldn't impose a memory footprint issue. + default-collection-context-buffer-size = 33792 + dispatchers { # Dispatcher for periodical gauge value recordings. diff --git a/kamon-core/src/main/scala/kamon/metric/EntityMetrics.scala b/kamon-core/src/main/scala/kamon/metric/EntityMetrics.scala index 325dd216..3761f5a5 100644 --- a/kamon-core/src/main/scala/kamon/metric/EntityMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metric/EntityMetrics.scala @@ -38,8 +38,8 @@ trait CollectionContext { } object CollectionContext { - def default: CollectionContext = new CollectionContext { - val buffer: LongBuffer = LongBuffer.allocate(10000) + def apply(longBufferSize: Int): CollectionContext = new CollectionContext { + val buffer: LongBuffer = LongBuffer.allocate(longBufferSize) } } diff --git a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala index 1025f0de..8c6d0359 100644 --- a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala +++ b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala @@ -57,14 +57,6 @@ class MetricsExtension(system: ExtendedActorSystem) extends Kamon.Extension { subscriptions.tell(Subscribe(category, selection, permanently), receiver) } - def collect: Map[MetricGroupIdentity, MetricGroupSnapshot] = { - // TODO: Improve the way in which we are getting the context. - val context = new CollectionContext { - val buffer: LongBuffer = LongBuffer.allocate(50000) - } - (for ((identity, recorder) ← storage) yield (identity, recorder.collect(context))).toMap - } - def scheduleGaugeRecorder(body: ⇒ Unit): Cancellable = { import scala.concurrent.duration._ @@ -98,6 +90,9 @@ class MetricsExtension(system: ExtendedActorSystem) extends Kamon.Extension { allFilters.toMap } + + def buildDefaultCollectionContext: CollectionContext = + CollectionContext(metricsExtConfig.getInt("default-collection-context-buffer-size")) } object Metrics extends ExtensionId[MetricsExtension] with ExtensionIdProvider { diff --git a/kamon-core/src/main/scala/kamon/metric/Subscriptions.scala b/kamon-core/src/main/scala/kamon/metric/Subscriptions.scala index a9f4c721..eb2168ad 100644 --- a/kamon-core/src/main/scala/kamon/metric/Subscriptions.scala +++ b/kamon-core/src/main/scala/kamon/metric/Subscriptions.scala @@ -30,6 +30,7 @@ class Subscriptions extends Actor { val config = context.system.settings.config val tickInterval = Duration(config.getDuration("kamon.metrics.tick-interval", TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS) val flushMetricsSchedule = context.system.scheduler.schedule(tickInterval, tickInterval, self, FlushMetrics)(context.dispatcher) + val collectionContext = Kamon(Metrics).buildDefaultCollectionContext var lastTick: Long = System.currentTimeMillis() var subscribedPermanently: Map[MetricGroupFilter, List[ActorRef]] = Map.empty @@ -55,7 +56,7 @@ class Subscriptions extends Actor { def flush(): Unit = { val currentTick = System.currentTimeMillis() - val snapshots = Kamon(Metrics).collect + val snapshots = collectAll() dispatchSelectedMetrics(lastTick, currentTick, subscribedPermanently, snapshots) dispatchSelectedMetrics(lastTick, currentTick, subscribedForOneShot, snapshots) @@ -64,6 +65,9 @@ class Subscriptions extends Actor { subscribedForOneShot = Map.empty } + def collectAll(): Map[MetricGroupIdentity, MetricGroupSnapshot] = + (for ((identity, recorder) ← Kamon(Metrics).storage) yield (identity, recorder.collect(collectionContext))).toMap + def dispatchSelectedMetrics(lastTick: Long, currentTick: Long, subscriptions: Map[MetricGroupFilter, List[ActorRef]], snapshots: Map[MetricGroupIdentity, MetricGroupSnapshot]): Unit = { @@ -90,7 +94,7 @@ object Subscriptions { class TickMetricSnapshotBuffer(flushInterval: FiniteDuration, receiver: ActorRef) extends Actor { val flushSchedule = context.system.scheduler.schedule(flushInterval, flushInterval, self, FlushBuffer)(context.dispatcher) - val collectionContext = CollectionContext.default + val collectionContext = Kamon(Metrics)(context.system).buildDefaultCollectionContext def receive = empty diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala index 9ae077f4..8c81e717 100644 --- a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala +++ b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala @@ -103,6 +103,8 @@ class HdrHistogram(lowestTrackableValue: Long, highestTrackableValue: Long, sign new CompactHdrSnapshot(scale, nrOfMeasurements, measurementsArray, unitMagnitude(), subBucketHalfCount(), subBucketHalfCountMagnitude()) } + def getCounts = countsArray().length() + def cleanup: Unit = {} private def writeSnapshotTo(buffer: LongBuffer): Long = { |