|
7 | 7 | use App\Entity\Judgehost;
|
8 | 8 | use App\Entity\JudgeTask;
|
9 | 9 | use App\Entity\Judging;
|
| 10 | +use App\Entity\JudgingRun; |
10 | 11 | use App\Form\Type\JudgehostsType;
|
11 | 12 | use App\Service\ConfigurationService;
|
12 | 13 | use App\Service\DOMJudgeService;
|
@@ -57,10 +58,23 @@ public function indexAction(Request $request): Response
|
57 | 58 | 'hostname' => ['title' => 'hostname'],
|
58 | 59 | 'enabled' => ['title' => 'enabled'],
|
59 | 60 | 'status' => ['title' => 'status'],
|
| 61 | + 'load' => ['title' => 'load (5m/15m/1h/5h)'], |
60 | 62 | 'last_judgingid' => ['title' => 'last judging'],
|
61 | 63 | ];
|
62 | 64 |
|
63 | 65 | $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(); |
64 | 78 |
|
65 | 79 | $propertyAccessor = PropertyAccess::createPropertyAccessor();
|
66 | 80 | $time_warn = $this->config->get('judgehost_warning');
|
@@ -117,6 +131,35 @@ public function indexAction(Request $request): Response
|
117 | 131 | 'value' => 'j' . $lastJobId['jobid'],
|
118 | 132 | ];
|
119 | 133 |
|
| 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 | + |
120 | 163 | $judgehostdata = array_merge($judgehostdata, [
|
121 | 164 | 'status' => [
|
122 | 165 | 'value' => $status,
|
|
0 commit comments