From a44a5bf281544976dab0a2b99c79e0c3b0463962 Mon Sep 17 00:00:00 2001 From: brharrington Date: Tue, 21 Feb 2023 18:58:49 -0600 Subject: [PATCH] aggr: use a single registry instance (#390) Having multiple registry instances was a simple way to get more concurrency. However, it creates additional overhead for loading expressions from LWC. There are other ways to acheive the concurrency needed now. --- .../aggregator/AtlasAggregatorService.scala | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/atlas-aggregator/src/main/scala/com/netflix/atlas/aggregator/AtlasAggregatorService.scala b/atlas-aggregator/src/main/scala/com/netflix/atlas/aggregator/AtlasAggregatorService.scala index d3ba2e82..9b3563fe 100644 --- a/atlas-aggregator/src/main/scala/com/netflix/atlas/aggregator/AtlasAggregatorService.scala +++ b/atlas-aggregator/src/main/scala/com/netflix/atlas/aggregator/AtlasAggregatorService.scala @@ -31,32 +31,27 @@ class AtlasAggregatorService( ) extends AbstractService with Aggregator { - private val n = math.max(1, Runtime.getRuntime.availableProcessors() / 2) private val aggrCfg = new AggrConfig(config, registry, system) - private val registries = (0 until n) - .map(_ => new AtlasRegistry(clock, aggrCfg)) - .toArray + private val aggrRegistry = new AtlasRegistry(clock, aggrCfg) override def startImpl(): Unit = { - registries.foreach(_.start()) + aggrRegistry.start() } override def stopImpl(): Unit = { - registries.foreach(_.stop()) + aggrRegistry.stop() } def lookup(id: Id): AtlasRegistry = { - // Max is needed because for Integer.MIN_VALUE the abs value will be negative - val i = math.max(math.abs(id.hashCode()), 0) % n - registries(i) + aggrRegistry } override def add(id: Id, value: Double): Unit = { - lookup(id).counter(id).add(value) + aggrRegistry.counter(id).add(value) } override def max(id: Id, value: Double): Unit = { - lookup(id).maxGauge(id).set(value) + aggrRegistry.maxGauge(id).set(value) } }