diff --git a/Client/bench.py b/Client/bench.py index cabf62a..3ec840a 100644 --- a/Client/bench.py +++ b/Client/bench.py @@ -32,12 +32,16 @@ import multiprocessing import os +import queue import re import subprocess import sys +from utils import kill_process_by_name from utils import OpenBenchBadBenchException +MAX_BENCH_TIME_SECONDS = 60 + def parse_stream_output(stream): nps = bench = None # Search through output Stream @@ -88,13 +92,23 @@ def multi_core_bench(binary, network, private, threads): processes = [ multiprocessing.Process( - target=single_core_bench, - args=(binary, network, private, outqueue) - ) for ii in range(threads) + target=single_core_bench, args=(binary, network, private, outqueue)) + for ii in range(threads) ] - for process in processes: process.start() - return [outqueue.get() for ii in range(threads)] + for process in processes: + 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): diff --git a/Client/genfens.py b/Client/genfens.py index 7d9a258..cc4c5a2 100644 --- a/Client/genfens.py +++ b/Client/genfens.py @@ -21,10 +21,10 @@ # The sole purpose of this module is to invoke create_genfens_opening_book(). # # This will execute engines with commands like the following: -# ./engine "genfens N seed S book " "quit" +# ./engine "genfens N seed S book " "quit" # # 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 # # create_genfens_opening_book() may raise utils.OpenBenchFailedGenfensException. diff --git a/Scripts/bench_all.py b/Scripts/bench_all.py index aaf6852..af837ef 100644 --- a/Scripts/bench_all.py +++ b/Scripts/bench_all.py @@ -160,5 +160,9 @@ if __name__ == '__main__': 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 - 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))) + try: + 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))