Skip to content

Commit 50060a8

Browse files
committed
enable support to set task execution time limit in WfBench (closes #33)
1 parent a52f922 commit 50060a8

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

wfcommons/wfbench/bench.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
4-
# Copyright (c) 2021-2022 The WfCommons Team.
4+
# Copyright (c) 2021-2023 The WfCommons Team.
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -79,6 +79,7 @@ def create_benchmark(self,
7979
percent_cpu: Union[float, Dict[str, float]] = 0.6,
8080
cpu_work: Union[int, Dict[str, int]] = None,
8181
gpu_work: Union[int, Dict[str, int]] = None,
82+
time: Optional[int] = None,
8283
data: Optional[Union[int, Dict[str, str]]] = None,
8384
mem: Optional[float] = None,
8485
lock_files_folder: Optional[pathlib.Path] = None,
@@ -91,6 +92,8 @@ def create_benchmark(self,
9192
:type percent_cpu: Union[float, Dict[str, float]]
9293
:param cpu_work: CPU work per workflow task.
9394
:type cpu_work: Union[int, Dict[str, int]]
95+
:param time: Time limit for running each task (in seconds).
96+
:type time: Optional[int]
9497
:param data: Dictionary of input size files per workflow task type or total workflow data footprint (in MB).
9598
:type data: Optional[Union[int, Dict[str, str]]]
9699
:param mem: Maximum amount of memory consumption per task (in MB).
@@ -155,6 +158,9 @@ def create_benchmark(self,
155158

156159
if mem:
157160
params.extend([f"--mem {mem}"])
161+
162+
if time:
163+
params.extend([f"--time {time}"])
158164

159165
task.runtime = 0
160166
task.files = []

wfcommons/wfbench/wfbench.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
4-
# Copyright (c) 2021-2022 The WfCommons Team.
4+
# Copyright (c) 2021-2023 The WfCommons Team.
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -14,9 +14,12 @@
1414
import subprocess
1515
import time
1616
import json
17-
from io import StringIO
17+
import signal
18+
import sys
1819
import pandas as pd
1920

21+
from io import StringIO
22+
2023
from filelock import FileLock
2124
from typing import List, Optional
2225

@@ -147,6 +150,7 @@ def get_parser() -> argparse.ArgumentParser:
147150
help="Path to cores file.")
148151
parser.add_argument("--cpu-work", default=None, help="Amount of CPU work.")
149152
parser.add_argument("--gpu-work", default=None, help="Amount of GPU work.")
153+
parser.add_argument("--time", default=None, help="Time limit (in seconds) to complete the task (overrides CPU and GPU works)")
150154
parser.add_argument("--mem", default=None, help="Max amount (in MB) of memory consumption.")
151155
parser.add_argument("--out", help="output files name.")
152156
return parser
@@ -193,7 +197,7 @@ def main():
193197
else:
194198
device = available_gpus[0]
195199
print(f"Running on GPU {device}")
196-
gpu_benchmark(args.gpu_work, device)
200+
gpu_benchmark(args.gpu_work, device, time=args.time)
197201

198202
if args.cpu_work:
199203
print("[WfBench] Starting CPU and Memory Benchmarks...")
@@ -202,11 +206,18 @@ def main():
202206

203207
cpu_procs = cpu_mem_benchmark(cpu_threads=int(10 * args.percent_cpu),
204208
mem_threads=int(10 - 10 * args.percent_cpu),
205-
cpu_work=int(args.cpu_work),
209+
cpu_work=sys.maxsize if args.time else int(args.cpu_work),
206210
core=core,
207211
total_mem=args.mem)
208-
for proc in cpu_procs:
209-
proc.wait()
212+
213+
if args.time:
214+
time.sleep(int(args.time))
215+
for proc in cpu_procs:
216+
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
217+
else:
218+
for proc in cpu_procs:
219+
proc.wait()
220+
210221
mem_kill = subprocess.Popen(["killall", "stress-ng"])
211222
mem_kill.wait()
212223
print("[WfBench] Completed CPU and Memory Benchmarks!\n")

0 commit comments

Comments
 (0)