Skip to content

Commit

Permalink
Remove cached binaries on worker startup
Browse files Browse the repository at this point in the history
as the user could change the compiler at worker startup time (e.g. clang vs gcc),
the binary cache might contain binaries compiled with a different compiler
than the ones generated by the worker. As different compilers lead to binaries of
different speed, test results could be biased, unless we assure that the same compiler
is used for both base and new test.

This patch just clears the binary cache once at worker startup,
leaving the caching mechanism unchanged otherwise.

fixes official-stockfish#1666
  • Loading branch information
vondele authored and ppigazzini committed Aug 20, 2023
1 parent d00af79 commit ad87dde
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ def launch_cutechess(
return task_alive


def run_games(worker_info, password, remote, run, task_id, pgn_file):
def run_games(worker_info, password, remote, run, task_id, pgn_file, clear_binaries):
# This is the main cutechess-cli driver.
# It is ok, and even expected, for this function to
# raise exceptions, implicitly or explicitly, if a
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def parse_options(s):
# Clean up old engines (keeping the num_bkps most recent).
worker_dir = Path(__file__).resolve().parent
testing_dir = worker_dir / "testing"
num_bkps = 50
num_bkps = 0 if clear_binaries else 50
try:
engines = sorted(
testing_dir.glob("stockfish_*" + EXE_SUFFIX),
Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 210, "updater.py": "PHFUVXcoxBFiW2hTqFN5q5WdAw2pK8uzFC7hyMUC3cLY5bGZPhL8TBGThtqDmcXd", "worker.py": "Rbz9q1bCKE2MsrtUV3ywqP8tci1ao531KY26g6ZreiLnS9OnYlRJXmGBZap84CG/", "games.py": "7m8vZuGULuOtXGPuw6pxnu8BEW4DYjcf7RyRhzwB2XyeL783gaEDSc/ZsIUq+1zg"}
{"__version": 210, "updater.py": "PHFUVXcoxBFiW2hTqFN5q5WdAw2pK8uzFC7hyMUC3cLY5bGZPhL8TBGThtqDmcXd", "worker.py": "VQgNFEcvtmOvmRaSYTiLOgXXQ9ZXx/Pvi1ZR16mjy6DgbxuO3rmLEsWb9odsGt1x", "games.py": "au3WiGyUAb26mcz5C2MhnU7rhe8X3JMEgnyUlo4aAH+dPjxnXCZrWh9xFjdNQoFZ"}
15 changes: 12 additions & 3 deletions worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,9 @@ def verify_worker_version(remote, username, password):
return True


def fetch_and_handle_task(worker_info, password, remote, lock_file, current_state):
def fetch_and_handle_task(
worker_info, password, remote, lock_file, current_state, clear_binaries
):
# This function should normally not raise exceptions.
# Unusual conditions are handled by returning False.
# If an immediate exit is necessary then one can set
Expand Down Expand Up @@ -1398,7 +1400,7 @@ def fetch_and_handle_task(worker_info, password, remote, lock_file, current_stat
api = remote + "/api/failed_task"
pgn_file = [None]
try:
run_games(worker_info, password, remote, run, task_id, pgn_file)
run_games(worker_info, password, remote, run, task_id, pgn_file, clear_binaries)
success = True
except FatalException as e:
message = str(e)
Expand Down Expand Up @@ -1611,14 +1613,20 @@ def worker():
# Start the main loop.
delay = INITIAL_RETRY_TIME
fish_exit = False
clear_binaries = True
while current_state["alive"]:
if (worker_dir / "fish.exit").is_file():
current_state["alive"] = False
print("Stopped by 'fish.exit' file")
fish_exit = True
break
success = fetch_and_handle_task(
worker_info, options.password, remote, lock_file, current_state
worker_info,
options.password,
remote,
lock_file,
current_state,
clear_binaries,
)
if not current_state["alive"]: # the user may have pressed Ctrl-C...
break
Expand All @@ -1632,6 +1640,7 @@ def worker():
safe_sleep(delay)
delay = min(MAX_RETRY_TIME, delay * 2)
else:
clear_binaries = False
delay = INITIAL_RETRY_TIME

print("Waiting for the heartbeat thread to finish...")
Expand Down

0 comments on commit ad87dde

Please sign in to comment.