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

Change Select JudgeServerLogic #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions judge/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import json
import logging
from urllib.parse import urljoin
from datetime import timedelta

import requests
from django.db import transaction, IntegrityError
from django.db.models import F
from django.db.models.expressions import ExpressionWrapper
from django.db.models.fields import FloatField
from django.utils import timezone

from account.models import User
from conf.models import JudgeServer
Expand Down Expand Up @@ -37,9 +41,9 @@ def __init__(self):

def __enter__(self) -> [JudgeServer, None]:
with transaction.atomic():
servers = JudgeServer.objects.select_for_update().filter(is_disabled=False).order_by("task_number")
servers = [s for s in servers if s.status == "normal"]
for server in servers:
health_time = timezone.now() - timedelta(seconds=6)
server = JudgeServer.objects.select_for_update().filter(is_disabled=False, last_heartbeat__gt=health_time).annotate(percent=ExpressionWrapper((1.0000 * F('task_number')) / F('cpu_core'), output_field=FloatField())).order_by("percent").first()
if server:
if server.task_number <= server.cpu_core * 2:
server.task_number = F("task_number") + 1
server.save(update_fields=["task_number"])
Expand Down