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.

Possibly the binary cache should also be flushed on worker update
(e.g. the architecture selection logic might change). This is not implemented.

fixes #1666
  • Loading branch information
vondele committed May 5, 2023
1 parent 52a4230 commit 49f9d6a
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 @@ -1088,7 +1088,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 @@ -1176,7 +1176,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": 202, "updater.py": "PHFUVXcoxBFiW2hTqFN5q5WdAw2pK8uzFC7hyMUC3cLY5bGZPhL8TBGThtqDmcXd", "worker.py": "P3WT0Yhdj/rQ3ZrZ327nM7JQz87NhZC7wggqnqizeJJPbFy49ayo9n7JHoL/7eqv", "games.py": "sgnOBQQ9sZz6AlBg1SP7B1btuY0/p1StAwUtmoVzQk1+I/PjphRKlh2ak4yIpzFP"}
{"__version": 202, "updater.py": "PHFUVXcoxBFiW2hTqFN5q5WdAw2pK8uzFC7hyMUC3cLY5bGZPhL8TBGThtqDmcXd", "worker.py": "n3LJaWtFmOYeT0jh7v3F/omUQzk3hILlWlK20T+0V2Monj9ZaFLzk58Wat21I0t/", "games.py": "rHw5y0xCbLthLgu1nnBt5n6Viul6M9yvUrpIprMKRtp6+59dQCoTO3WOXoOPKHS3"}
15 changes: 12 additions & 3 deletions worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,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 @@ -1372,7 +1374,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 @@ -1585,14 +1587,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 @@ -1606,6 +1614,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 49f9d6a

Please sign in to comment.