Limit benching to 60s, before killing engines/threads and raising an exception (#225)

Adds a fourth possible OpenBenchBadBenchException exception during benching, for exceeding the max bench duration. This ensures that engines that infinitely stall, do not also lock up OpenBench clients. Additionally, make sure to clean up possible zombie processes that existed even in the case of a proper bench.
This commit is contained in:
Andrew Grant authored and GitHub committed 2024-06-17 11:53:45 -04:00
1 parent e2673c3cd1
commit 9e94da6b1f
3 files changed
+27 -9

No files matched your search

+19 -5
View File
@@ -32,12 +32,16 @@
import multiprocessing import multiprocessing
import os import os
import queue
import re import re
import subprocess import subprocess
import sys import sys
from utils import kill_process_by_name
from utils import OpenBenchBadBenchException from utils import OpenBenchBadBenchException
MAX_BENCH_TIME_SECONDS = 60
def parse_stream_output(stream): def parse_stream_output(stream):
nps = bench = None # Search through output Stream nps = bench = None # Search through output Stream
@@ -88,13 +92,23 @@ def multi_core_bench(binary, network, private, threads):
processes = [ processes = [
multiprocessing.Process( multiprocessing.Process(
target=single_core_bench, target=single_core_bench, args=(binary, network, private, outqueue))
args=(binary, network, private, outqueue) for ii in range(threads)
) for ii in range(threads)
] ]
for process in processes: process.start() for process in processes:
return [outqueue.get() for ii in range(threads)] process.start()
try: # Every process deposits exactly one result into the Queue
return [outqueue.get(timeout=MAX_BENCH_TIME_SECONDS) for ii in range(threads)]
except queue.Empty: # Force kill the engine, thus causing the processes to finish
kill_process_by_name(binary)
raise OpenBenchBadBenchException('[%s] Bench Exceeded Max Duration' % (binary))
finally: # Join everything to avoid zombie processes
for process in processes:
process.join()
def run_benchmark(binary, network, private, threads, sets, expected=None): def run_benchmark(binary, network, private, threads, sets, expected=None):
+2 -2
View File
@@ -21,10 +21,10 @@
# The sole purpose of this module is to invoke create_genfens_opening_book(). # The sole purpose of this module is to invoke create_genfens_opening_book().
# #
# This will execute engines with commands like the following: # This will execute engines with commands like the following:
# ./engine "genfens N seed S book <None|Books/book.epd> <?exta>" "quit" # ./engine "genfens N seed S book <None|Books/book.epd> <?extra>" "quit"
# #
# This work is split over many engines. If a workload requires 1024 openings, # This work is split over many engines. If a workload requires 1024 openings,
# and there are 16 threads, then each thread will generate 128 openings. The # and there are 16 threads, then each thread will generate 64 openings. The
# openings are saved to Books/openbench.genfens.epd # openings are saved to Books/openbench.genfens.epd
# #
# create_genfens_opening_book() may raise utils.OpenBenchFailedGenfensException. # create_genfens_opening_book() may raise utils.OpenBenchFailedGenfensException.
+6 -2
View File
@@ -160,5 +160,9 @@ if __name__ == '__main__':
private_net = configs[engine]['private'] and configs[engine].get('network') private_net = configs[engine]['private'] and configs[engine].get('network')
net_path = os.path.join('Networks', configs[engine]['network']['sha']) if private_net else None net_path = os.path.join('Networks', configs[engine]['network']['sha']) if private_net else None
nps, nodes = run_benchmark(bin_path, net_path, private_net, args.threads, args.sets) try:
print (print_format % (engine, nps, nodes, nodes / max(1e-6, nps))) nps, nodes = run_benchmark(bin_path, net_path, private_net, args.threads, args.sets)
print (print_format % (engine, nps, nodes, nodes / max(1e-6, nps)))
except OpenBenchBadBenchException as error:
print ('%s: %s' % (engine, error))