Overhaul Client Reporting mechanism (#153)

Collects results as game-pairs, instead of as individual results. This removes some noise and bias that may have existed prior.

The master thread now handles all reporting to the OpenBench server. Help threads, ( one for each --nsockets or -N ), will place their results in a multiprocessing.Queue().

We will report report_rate-pairs at a time. However we will only report up to once every 30 seconds. This means we might batch report many many games at a time. This acts as a natural remedy to if someone were to have created an insanely short time control, or low nodes test. This will cause fixed-game tests to go over the cap. IE, a 40,000 game test is very likely to receive a small number of games above 40,000. Fixing these seems non-trivial, and also not important.

The Client also sends Pentanomial information to the server now. This information is not acted upon.

This involved a complete rewrite of how data (trinomial) information is extracted from Cutechess. It is predicated upon the assertion that cutechess pairs are sequential. IE, pair one will be game 1/2. Pair two will be games 3/4. Etc. This is the fundemental assertion that is in Fishtest, although very confusing to extract from observation.

Resolves an issue where the worker threads, spawned to run benchmarks, were not being killed, as .start() was not followed by a .join().

Makes more cleanly aborting threads, by explicitly murdering them with an abort_flag from threading.Event(). This speeds up killing workers that have multi-sockets. It also helps further protect us against Cutechess being left open.

Performs atomic transactions with the database for tests. This is critical for dealing with future SPSA efforts. Updates to Profile, individual Result, and Machine, are left as is. This is because Model.objects.filter().update() is atomic, and the contents of Results are hit by only 1-thread at a time, and Profile/Machine's updates do not matter.

Resolves #144 and then some.
This commit is contained in:
Andrew Grant authored and GitHub committed 2023-08-16 08:02:56 -04:00
1 parent 3b4103baf7
commit d32761c53c
3 files changed
+265 -117

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ REQUIRE_MANUAL_REGISTRATION = False # Disable the public facing registration pag
OPENBENCH_CONFIG = {
# Server Client version control
'client_version' : '11',
'client_version' : '12',
# Generic Error Messages useful to those setting up their own instance
'error' : {
+55 -50
View File
@@ -30,6 +30,7 @@ import requests
from django.contrib.auth import authenticate
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage
from django.db import transaction
from django.db.models import F
from django.http import FileResponse
from django.utils import timezone
@@ -816,71 +817,75 @@ def workload_to_dictionary(test, result):
def update_test(request, machine):
# New results from the Worker
wins = int(request.POST['wins' ])
losses = int(request.POST['losses' ])
draws = int(request.POST['draws' ])
crashes = int(request.POST['crashes' ])
timeloss = int(request.POST['timeloss'])
games = wins + losses + draws
# Extract error information
crashes = int(request.POST['crashes' ])
timelosses = int(request.POST['timelosses'])
illegals = int(request.POST['illegals' ])
has_error = crashes or timelosses or illegals
# Worker knows where to save the results
machineid = int(request.POST['machine_id'])
resultid = int(request.POST['result_id' ])
testid = int(request.POST['test_id' ])
# Extract Database information
machine_id = int(request.POST['machine_id'])
result_id = int(request.POST['result_id' ])
test_id = int(request.POST['test_id' ])
# Prevent updating a finished test
test = Test.objects.get(id=testid)
if test.finished or test.deleted:
return { 'stop' : True }
# Trinomial Implementation
losses, draws, wins = map(int, request.POST['trinomial'].split())
games = losses + draws + wins
# Tally up the updated WLD stats
swins = test.wins + wins
slosses = test.losses + losses
sdraws = test.draws + draws
sgames = swins + slosses + sdraws
# Pentanomial Implementation
# ll, dl, dd, dw, ww = map(int, request.POST['pentanomial'].split())
# games = ll + dl + dd + dw + ww
if test.test_mode == 'SPRT':
with transaction.atomic():
# Compute a new LLR for the updated results
WLD = (swins, slosses, sdraws)
sprt = SPRT(*WLD, test.elolower, test.eloupper)
test = Test.objects.get(id=test_id)
if test.finished or test.deleted:
return { 'stop' : True }
# Check for H0 or H1 being accepted
passed = sprt > test.upperllr
failed = sprt < test.lowerllr
finished = passed or failed
test.losses += losses
test.draws += draws
test.wins += wins
test.games += games
if test.test_mode == 'GAMES':
test.error = test.error or has_error
# Finish test once we've played the proper amount of games
passed = sgames >= test.max_games and swins >= slosses
failed = sgames >= test.max_games and swins < slosses
finished = passed or failed
sprt = 0.0 # Hack to "update" the currentllr
if test.test_mode == 'SPRT':
# Update total games played by the Player
Profile.objects.filter(user=machine.user).update(games=F('games') + games)
Profile.objects.get(user=machine.user).save()
# Compute a new LLR for the updated results
WLD = (test.wins, test.losses, test.draws)
test.sprt = SPRT(*WLD, test.elolower, test.eloupper)
# Update the datetime in the Machine
machine.save()
# Check for H0 or H1 being accepted
test.passed = sprt > test.upperllr
test.failed = sprt < test.lowerllr
test.finished = passed or failed
# Update individual Result entry for the Player
Result.objects.filter(id=resultid).update(
elif test.test_mode == 'GAMES':
# Finish test once we've played the proper amount of games
test.passed = test.games >= test.max_games and test.wins >= test.losses
test.failed = test.games >= test.max_games and test.wins < test.losses
test.finished = test.passed or test.failed
test.save()
# Update Result object; No risk from concurrent access
Result.objects.filter(id=result_id).update(
games = F('games') + games, wins = F('wins' ) + wins,
losses = F('losses') + losses, draws = F('draws' ) + draws,
crashes = F('crashes') + crashes, timeloss = F('timeloss') + timeloss,
crashes = F('crashes') + crashes, timeloss = F('timeloss') + timelosses,
updated=timezone.now()
)
# Update the overall test with the new data
Test.objects.filter(id=testid).update(
games = F('games' ) + games, wins = F('wins' ) + wins,
losses = F('losses') + losses, draws = F('draws') + draws,
currentllr=sprt, passed=passed, failed=failed, finished=finished,
# Update Profile object; No risk from concurrent access
Profile.objects.filter(user=Machine.objects.get(id=machine_id).user).update(
games=F('games') + games,
updated=timezone.now()
)
# Force a refresh of the updated field when finished
if finished: Test.objects.get(id=testid).save()
# Update Machine object; No risk from concurrent access
Machine.objects.filter(id=machine_id).update(
updated=timezone.now()
)
return [{}, {'stop' : True}][finished]
return [{}, { 'stop' : True }][test.finished]