Skip to content

Commit

Permalink
flag to disable the scheduler coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Feb 29, 2024
1 parent e7883b0 commit 34de128
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions kyo-core/jvm/src/main/scala/kyo/scheduler/Coordinator.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package kyo.scheduler

import java.util.concurrent.Executor
import java.util.concurrent.Executors
import jdk.internal.vm.annotation.Contended
import scala.util.control.NonFatal

private object Coordinator:

private val enable = Flag("coordinator.enable", true)
private val cycleExp = Flag("coordinator.cycleExp", 8)
private val loadAvgTarget = Flag("coordinator.loadAvgTarget", 0.8)
private val jitterMax = Flag("coordinator.jitterMax", 0.1)
Expand All @@ -20,13 +22,15 @@ private object Coordinator:
private var startNs = 0L
private val delayNs = new MovingStdDev(cycleExp)

private val exec = Executors.newCachedThreadPool(Threads("kyo-coordinator"))
if enable then
val exec = Executors.newCachedThreadPool(Threads("kyo-coordinator"))

exec.execute { () =>
startNs = System.nanoTime()
while true do
update()
}
exec.execute { () =>
startNs = System.nanoTime()
while true do
update(exec)
}
end if

def load(): Unit = {}
def tick(): Long = ticks
Expand All @@ -35,7 +39,7 @@ private object Coordinator:
private def jitter() =
delayNs.dev().doubleValue() / 1000000

private def update() =
private def update(exec: Executor) =
try
Thread.sleep(1)
ticks += 1
Expand Down

0 comments on commit 34de128

Please sign in to comment.