Skip to content

Commit 9edfdb4

Browse files
committed
Add simple load numbers to judgedaemon overview page.
Part of #1164
1 parent 164d76b commit 9edfdb4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

webapp/src/Controller/Jury/JudgehostController.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Judgehost;
88
use App\Entity\JudgeTask;
99
use App\Entity\Judging;
10+
use App\Entity\JudgingRun;
1011
use App\Form\Type\JudgehostsType;
1112
use App\Service\ConfigurationService;
1213
use App\Service\DOMJudgeService;
@@ -57,10 +58,23 @@ public function indexAction(Request $request): Response
5758
'hostname' => ['title' => 'hostname'],
5859
'enabled' => ['title' => 'enabled'],
5960
'status' => ['title' => 'status'],
61+
'load' => ['title' => 'load (5m/15m/1h/5h)'],
6062
'last_judgingid' => ['title' => 'last judging'],
6163
];
6264

6365
$now = Utils::now();
66+
$timings = $this->em->createQueryBuilder()
67+
->from(JudgeTask::class, 'jt')
68+
->join(JudgingRun::class, 'jr', 'WITH', 'jr.judgetask = jt')
69+
->join('jr.judging', 'j')
70+
->join('jt.judgehost', 'jh')
71+
->select('jh.judgehostid, jr.endtime, jr.startTime')
72+
->andWhere('jr.startTime IS NOT NULL')
73+
->andWhere('jr.endtime IS NOT NULL')
74+
->andWhere('jr.endtime >= :five_hours_ago')
75+
->setParameter('five_hours_ago', $now - 5*60*60)
76+
->getQuery()
77+
->getResult();
6478

6579
$propertyAccessor = PropertyAccess::createPropertyAccessor();
6680
$time_warn = $this->config->get('judgehost_warning');
@@ -117,6 +131,35 @@ public function indexAction(Request $request): Response
117131
'value' => 'j' . $lastJobId['jobid'],
118132
];
119133

134+
$loads = [0.0, 0.0, 0.0, 0.0];
135+
$loadMinutes = [60*5, 60*15, 60*60, 60*300];
136+
$loadStart = [];
137+
for ($i = 0; $i < 4; $i++) {
138+
$loadStart[] = $now - $loadMinutes[$i];
139+
}
140+
foreach ($timings as $timing) {
141+
if ($timing['judgehostid'] !== $judgehost->getJudgehostid()) {
142+
continue;
143+
}
144+
for ($i = 0; $i < 4; $i++) {
145+
$start_time = $timing['startTime'];
146+
$end_time = $timing['endtime'];
147+
$start_time = max($start_time, $loadStart[$i]);
148+
if ($start_time < $end_time) {
149+
$loads[$i] += ($end_time - $start_time);
150+
}
151+
}
152+
}
153+
// Normalize to [0,1] range.
154+
for ($i = 0; $i < 4; $i++) {
155+
$loads[$i] = min(1.0, $loads[$i] / $loadMinutes[$i]);
156+
}
157+
$judgehostdata['load'] = [
158+
'value' => sprintf('%.2f / %.2f / %.2f / %.2f', $loads[0], $loads[1], $loads[2], $loads[3]),
159+
'title' => 'estimated load (5m/15m/1h/5h)',
160+
'cssclass' => 'text-monospace',
161+
];
162+
120163
$judgehostdata = array_merge($judgehostdata, [
121164
'status' => [
122165
'value' => $status,

0 commit comments

Comments
 (0)