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

scheduler top improvements #369

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
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
48 changes: 36 additions & 12 deletions kyo-scheduler/jvm/src/main/scala/kyo/scheduler/Scheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Scheduler.*
import java.util.concurrent.Executor
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.LongAdder
import kyo.scheduler.regulator.Admission
Expand Down Expand Up @@ -219,18 +220,32 @@ final class Scheduler(
}

def status(): Scheduler.Status = {
val workersStatus =
for (i <- 0 until allocatedWorkers) yield workers(i) match {
case null => null
case worker =>
worker.status()
def workerStatus(i: Int) = {
workers(i) match {
case null => null
case worker => worker.status()
}
}
val activeWorkers =
(0 until currentWorkers).map(workerStatus)
val inactiveWorkers =
(currentWorkers until allocatedWorkers).map(workerStatus)
val (activeThreads, totalThreads) =
workerExecutor match {
case exec: ThreadPoolExecutor =>
(exec.getActiveCount(), exec.getPoolSize())
case _ =>
(-1, -1)
}
Scheduler.Status(
currentWorkers,
allocatedWorkers,
loadAvg(),
flushes.sum(),
workersStatus,
activeThreads,
totalThreads,
activeWorkers,
inactiveWorkers,
admissionRegulator.status(),
concurrencyRegulator.status()
)
Expand All @@ -244,21 +259,30 @@ object Scheduler {
allocatedWorkers: Int,
loadAvg: Double,
flushes: Long,
workers: Seq[WorkerStatus],
activeThreads: Int,
totalThreads: Int,
activeWorkers: Seq[WorkerStatus],
inactiveWorkers: Seq[WorkerStatus],
admission: Admission.AdmissionStatus,
concurrency: Concurrency.AdmissionStatus
) {
private def delta(a: Seq[WorkerStatus], b: Seq[WorkerStatus]) =
a.zipAll(b, null, null).map {
case (a, null) => a
case (null, b) => b
case (a, b) => a - b
}

infix def -(other: Status): Status =
Status(
currentWorkers,
allocatedWorkers,
loadAvg,
flushes - other.flushes,
workers.zipAll(other.workers, null, null).map {
case (a, null) => a
case (null, b) => b
case (a, b) => a - b
},
activeThreads,
totalThreads,
delta(activeWorkers, other.activeWorkers),
delta(inactiveWorkers, other.inactiveWorkers),
admission - other.admission,
concurrency - other.concurrency
)
Expand Down
39 changes: 21 additions & 18 deletions kyo-scheduler/jvm/src/main/scala/kyo/scheduler/util/Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import javax.management.remote.JMXConnectorFactory
import javax.management.remote.JMXServiceURL
import kyo.scheduler.InternalTimer
import kyo.scheduler.Scheduler
import kyo.scheduler.WorkerStatus
import scala.annotation.nowarn
import scala.concurrent.duration.*
import scala.io.StdIn
Expand Down Expand Up @@ -94,52 +95,54 @@ object Top extends App {
val sb = new StringBuilder()

sb.append(f"""
|===============================================================================================
|Kyo Scheduler Status | LoadAvg: ${status.loadAvg}%1.4f | Flushes: ${status.flushes}
|===============================================================================================
|Regulator | %% | Allow | Reject | Probes | Cmpl | Adjmts | Updts | Avg | Jitter
|-----------------------------------------------------------------------------------------------
|╔═══════════════════════════════════════════════════════════════════════════════════════════════════╗
|║ *..*..*. *. .. * * * .*. Kyo Scheduler Top . . * . * . * * .*. .*. ...*. ║
|╚═══════════════════════════════════════════════════════════════════════════════════════════════════╝
Comment on lines +98 to +100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that's left are some pretty colors for increases/decreases in utilization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that'd be cool! :)

| LoadAvg: ${status.loadAvg}%1.4f Flushes: ${status.flushes} Threads: ${status.activeThreads}/${status.totalThreads} (active/total)
|=====================================================================================================
| Regulator | %% | Allow | Reject | Probes | Cmpl | Adjmts | Updts | Avg | Jitter
|-----------------------------------------------------------------------------------------------------
|""".stripMargin)

// Admission regulator row
val admission = status.admission
val admissionAvg = f"${admission.regulator.measurementsAvg}%7.1f"
val admissionJitter = f"${admission.regulator.measurementsJitter}%7.2f"
sb.append(
f"Admission | ${admission.admissionPercent}%3d | ${admission.allowed}%5d | ${admission.rejected}%6d | ${admission.regulator.probesSent}%6d | ${admission.regulator.probesCompleted}%5d | ${admission.regulator.adjustments}%6d | ${admission.regulator.updates}%5d | $admissionAvg%9s | $admissionJitter%8s\n"
f" Admission | ${admission.admissionPercent}%3d | ${admission.allowed}%5d | ${admission.rejected}%6d | ${admission.regulator.probesSent}%6d | ${admission.regulator.probesCompleted}%5d | ${admission.regulator.adjustments}%6d | ${admission.regulator.updates}%5d | $admissionAvg%9s | $admissionJitter%8s\n"
)

// Concurrency regulator row
val concurrency = status.concurrency
val concurrencyAvg = f"${concurrency.regulator.measurementsAvg}%7.1f"
val concurrencyJitter = f"${concurrency.regulator.measurementsJitter}%7.2f"
sb.append(
f"Concurrency | - | - | - | ${concurrency.regulator.probesSent}%6d | ${concurrency.regulator.probesCompleted}%5d | ${concurrency.regulator.adjustments}%6d | ${concurrency.regulator.updates}%5d | $concurrencyAvg%9s | $concurrencyJitter%8s\n"
f" Concurrency | - | - | - | ${concurrency.regulator.probesSent}%6d | ${concurrency.regulator.probesCompleted}%5d | ${concurrency.regulator.adjustments}%6d | ${concurrency.regulator.updates}%5d | $concurrencyAvg%9s | $concurrencyJitter%8s\n"
)

sb.append(f"""
|===============================================================================================
|Worker | Running | Blocked | Stalled | Load | Exec | Preempt | Done | Stolen | Lost | Thread
|-----------------------------------------------------------------------------------------------
|=====================================================================================================
| Worker | Running | Blocked | Stalled | Load | Exec | Done | Preempt | Stolen | Lost | Thread
|-----------------------------------------------------------------------------------------------------
|""".stripMargin)

// Worker table rows
status.workers.foreach { w =>
def print(w: WorkerStatus) =
if (w ne null) {
val running = if (w.running) " 🏃 " else " ⚫ "
val blocked = if (w.isBlocked) " 🚧 " else " ⚫ "
val stalled = if (w.isStalled) " 🐢 " else " ⚫ "

sb.append(
f"${w.id}%6d | $running | $blocked%-2s | $stalled%-2s | ${w.load}%5d | ${w.executions}%5d | ${w.preemptions}%7d | ${w.completions}%5d | ${w.stolenTasks}%6d | ${w.lostTasks}%4d | ${w.mount} ${w.frame}\n"
f" ${w.id}%6d | $running | $blocked%-2s | $stalled%-2s | ${w.load}%5d | ${w.executions}%8d | ${w.completions}%8d | ${w.preemptions}%5d | ${w.stolenTasks}%6d | ${w.lostTasks}%4d | ${w.mount} ${w.frame}\n"
)
}
}

sb.append("\n")

// Regulator table header
sb.append("================================================================================================\n")
status.activeWorkers.foreach(print)
if (status.inactiveWorkers.nonEmpty) {
sb.append("------------------------------------- Inactive ------------------------------------------------\n")
status.inactiveWorkers.foreach(print)
}
sb.append("=====================================================================================================\n")

sb.toString()
}
Expand Down
Loading