Skip to content

Commit c0ede14

Browse files
committed
feat: add memory limit to wfbench.py
1 parent 1bde636 commit c0ede14

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

wfcommons/wfbench/wfbench.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,30 @@ def get_parser() -> argparse.ArgumentParser:
156156
return parser
157157

158158

159-
def io_read_benchmark_user_input_data_size(inputs):
159+
def io_read_benchmark_user_input_data_size(inputs, memory_limit=None):
160+
if memory_limit is None:
161+
memory_limit = -1
162+
memory_limit = int(memory_limit)
160163
print("[WfBench] Starting IO Read Benchmark...")
161164
for file in inputs:
162165
with open(file, "rb") as fp:
163166
print(f"[WfBench] Reading '{file}'")
164-
fp.readlines()
167+
while fp.read(memory_limit):
168+
pass
165169
print("[WfBench] Completed IO Read Benchmark!\n")
166170

167171

168-
def io_write_benchmark_user_input_data_size(outputs):
172+
def io_write_benchmark_user_input_data_size(outputs, memory_limit=None):
173+
if memory_limit is None:
174+
memory_limit = sys.maxsize
175+
memory_limit = int(memory_limit)
169176
for file_name, file_size in outputs.items():
170177
print(f"[WfBench] Writing output file '{file_name}'\n")
171-
with open(file_name, "wb") as fp:
172-
fp.write(os.urandom(int(file_size)))
178+
file_size_todo = file_size
179+
while file_size_todo > 0:
180+
with open(file_name, "ab") as fp:
181+
chunk_size = min(file_size_todo, memory_limit)
182+
file_size_todo -= fp.write(os.urandom(int(chunk_size)))
173183

174184

175185
def main():
@@ -186,7 +196,7 @@ def main():
186196
print(f"[WfBench] Starting {args.name} Benchmark\n")
187197

188198
if args.out:
189-
io_read_benchmark_user_input_data_size(other)
199+
io_read_benchmark_user_input_data_size(other, memory_limit=args.mem)
190200

191201
if args.gpu_work:
192202
print("[WfBench] Starting GPU Benchmark...")
@@ -224,7 +234,7 @@ def main():
224234

225235
if args.out:
226236
outputs = json.loads(args.out.replace("'", '"'))
227-
io_write_benchmark_user_input_data_size(outputs)
237+
io_write_benchmark_user_input_data_size(outputs, memory_limit=args.mem)
228238

229239
if core:
230240
unlock_core(path_locked, path_cores, core)

0 commit comments

Comments
 (0)