Concurrency

kyo.scheduler.regulator.Concurrency
See theConcurrency companion object
final class Concurrency(loadAvg: DoubleSupplier, updateConcurrency: Int => Unit, sleep: Int => Unit, nowNanos: LongSupplier, timer: InternalTimer, config: Config) extends Regulator

Concurrency control regulator that optimizes thread count by detecting system scheduling delays.

The Concurrency regulator maintains optimal performance by measuring the system's ability to promptly execute threads. It uses a dedicated OS thread to perform brief sleep operations, analyzing delays between requested and actual wake times to detect various forms of contention and interference. This approach is similar to the jHiccup tool, but uses standard deviation analysis via the Regulator framework to make automatic adjustments.

The probe mechanism relies on the operating system's thread scheduling behavior. In a healthy system, the probe thread wakes up from sleep very close to the requested time. Various conditions can delay thread wake-ups, including OS scheduler overload, CPU throttling, excessive context switching, hypervisor interference, and hardware power management. By measuring these delays, the regulator detects when the system is struggling to handle the current thread count.

When wake-up delays show high jitter, indicating degraded thread scheduling, the regulator reduces the number of workers. When delays are consistent and the system maintains its target load, the regulator gradually increases workers. This approach automatically finds the optimal thread count for the current system conditions and available CPU resources.

Value parameters

config

Configuration parameters controlling concurrency adjustment

loadAvg

A supplier that provides the current system load average

nowNanos

Current time supplier for wake-up delay measurements

sleep

Function to perform sleep probes (must use OS thread sleep)

timer

Timer for scheduling periodic regulation

updateConcurrency

Callback to update the number of worker threads

Attributes

See also

Regulator for details on the underlying regulation mechanism

Companion
object
Graph
Supertypes
class Regulator
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

Inherited methods

protected def measure(v: Long): Unit

Record a measurement value for regulation.

Record a measurement value for regulation.

Value parameters

v

The measurement value in nanoseconds Measurements are used to:

  • Calculate jitter (standard deviation)
  • Detect performance anomalies
  • Guide adjustment decisions

Attributes

Inherited from:
Regulator
protected def regulatorStatus(): RegulatorStatus

Attributes

Inherited from:
Regulator
def stop(): Unit

Stop the regulator.

Stop the regulator.

Cancels all scheduled tasks and cleans up resources.

Attributes

Inherited from:
Regulator

Inherited fields

protected val statsScope: Scope

Attributes

Inherited from:
Regulator