Skip to content

Send less event updates for judgements in parallel mode. #2523

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

Merged
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
36 changes: 36 additions & 0 deletions webapp/migrations/Version20241122150726.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241122150726 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add max runtime for verdict to judging';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judging ADD max_runtime_for_verdict NUMERIC(32, 9) UNSIGNED DEFAULT NULL COMMENT \'The maximum run time for all runs that resulted in the verdict\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judging DROP max_runtime_for_verdict');
}

public function isTransactional(): bool
{
return false;
}
}
21 changes: 19 additions & 2 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,26 @@ private function addSingleJudgingRun(
if (!$hasNullResults || $lazyEval !== DOMJudgeService::EVAL_FULL) {
// NOTE: setting endtime here determines in testcases_GET
// whether a next testcase will be handed out.
$judging->setEndtime(Utils::now());
// We want to set the endtime and max runtime only once (once the verdict is known),
// so that the API doesn't update these values once they are set.
// We also don't want to send judging events after the verdict is known.
if (!$judging->getEndtime()) {
$sendJudgingEvent = true;
$judging->setEndtime(Utils::now());

// Also calculate the max run time and set it
$maxRunTime = $this->em->createQueryBuilder()
->from(Judging::class, 'j')
->select('MAX(jr.runtime) AS maxruntime')
->leftJoin('j.runs', 'jr')
->andWhere('j.judgingid = :judgingid')
->andWhere('jr.runtime IS NOT NULL')
->setParameter('judgingid', $judging->getJudgingid())
->getQuery()
->getSingleScalarResult();
$judging->setMaxRuntimeForVerdict($maxRunTime);
}
$this->maybeUpdateActiveJudging($judging);
$sendJudgingEvent = true;
}
$this->em->flush();

Expand Down
8 changes: 3 additions & 5 deletions webapp/src/Controller/API/JudgementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function getQueryBuilder(Request $request): QueryBuilder
{
$queryBuilder = $this->em->createQueryBuilder()
->from(Judging::class, 'j')
->select('j, c, s, MAX(jr.runtime) AS maxruntime')
->select('j, c, s')
->leftJoin('j.contest', 'c')
->leftJoin('j.submission', 's')
->leftJoin('j.rejudging', 'r')
Expand Down Expand Up @@ -161,12 +161,10 @@ protected function getIdField(): string
return 'j.judgingid';
}

public function transformObject($object): JudgingWrapper
public function transformObject($judging): JudgingWrapper
{
/** @var Judging $judging */
$judging = $object[0];
$maxRunTime = $object['maxruntime'] === null ? null : (float)$object['maxruntime'];
$judgementTypeId = $judging->getResult() ? $this->verdicts[$judging->getResult()] : null;
return new JudgingWrapper($judging, $maxRunTime, $judgementTypeId);
return new JudgingWrapper($judging, $judgementTypeId);
}
}
10 changes: 0 additions & 10 deletions webapp/src/DataTransferObject/JudgingWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ class JudgingWrapper
public function __construct(
#[Serializer\Inline]
protected readonly Judging $judging,
#[Serializer\Exclude]
protected readonly ?float $maxRunTime = null,
#[Serializer\SerializedName('judgement_type_id')]
protected readonly ?string $judgementTypeId = null
) {}

#[Serializer\VirtualProperty]
#[Serializer\SerializedName('max_run_time')]
#[Serializer\Type('float')]
public function getMaxRunTime(): ?float
{
return Utils::roundedFloat($this->maxRunTime);
}
}
30 changes: 30 additions & 0 deletions webapp/src/Entity/Judging.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class Judging extends BaseApiEntity
#[Serializer\Exclude]
private string|float|null $endtime = null;

#[ORM\Column(
type: 'decimal',
precision: 32,
scale: 9,
nullable: true,
options: ['comment' => 'The maximum runtime for all runs that resulted in the verdict', 'unsigned' => true]
)]
#[Serializer\Exclude]
private string|float|null $maxRuntimeForVerdict = null;

#[ORM\Column(
length: 32,
nullable: true,
Expand Down Expand Up @@ -250,6 +260,26 @@ public function getRelativeEndTime(): ?string
return $this->getEndtime() ? Utils::relTime($this->getEndtime() - $this->getContest()->getStarttime()) : null;
}

public function setMaxRuntimeForVerdict(string|float $maxRuntimeForVerdict): Judging
{
$this->maxRuntimeForVerdict = $maxRuntimeForVerdict;
return $this;
}

public function getMaxRuntimeForVerdict(): string|float|null
{
return $this->maxRuntimeForVerdict;
}

#[Serializer\VirtualProperty]
#[Serializer\SerializedName('max_run_time')]
#[Serializer\Type('float')]
#[OA\Property(nullable: true)]
public function getRoundedMaxRuntimeForVerdict(): ?float
{
return $this->maxRuntimeForVerdict ? Utils::roundedFloat((float)$this->maxRuntimeForVerdict) : null;
}

public function setResult(?string $result): Judging
{
$this->result = $result;
Expand Down
Loading