Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggr: use a single registry instance #390

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}