Skip to content

Commit

Permalink
flush stdout before running subprocess, so things print in order
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Oct 7, 2023
1 parent db87b79 commit a473549
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-c/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
subprocess.run(cmd_args, check=True)


Expand Down
7 changes: 4 additions & 3 deletions runners/s3-benchrunner-cli/benchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _using_all_files_in_dir(self, action: str, prefix: str) -> bool:
paginator = s3.get_paginator('list_objects_v2')
for page in paginator.paginate(Bucket=self.bucket, Prefix=prefix):
for obj in page['Contents']:
if obj['Key'] in all_task_keys:
if not obj['Key'] in all_task_keys:
return False

else: # upload
Expand All @@ -252,7 +252,7 @@ def run(self):
'input': self._stdin_for_cli}
if self.verbose:
# show live output, and immediately raise exception if process fails
print(f'> {subprocess.list2cmdline(self._cli_cmd)}')
print(f'> {subprocess.list2cmdline(self._cli_cmd)}', flush=True)
run_kwargs['check'] = True
else:
# capture output, and only print if there's an error
Expand Down Expand Up @@ -288,7 +288,8 @@ def run(self):
f'Gb/s:{bytes_to_gigabit(bytes_per_run) / run_secs:.3f} ' +
f'Mb/s:{bytes_to_megabit(bytes_per_run) / run_secs:.3f} ' +
f'GiB/s:{bytes_to_GiB(bytes_per_run) / run_secs:.3f} ' +
f'MiB/s:{bytes_to_MiB(bytes_per_run) / run_secs:.3f}')
f'MiB/s:{bytes_to_MiB(bytes_per_run) / run_secs:.3f}',
flush=True)

# Break out if we've exceeded max_repeat_secs
app_secs = ns_to_secs(time.perf_counter_ns() - app_start_ns)
Expand Down
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-cli/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
subprocess.run(cmd_args, check=True)


Expand Down
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-crt-java/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
subprocess.run(cmd_args, check=True)


Expand Down
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-crt-java/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
if subprocess.run(cmd_args).returncode != 0:
exit('FAILED')

Expand Down
21 changes: 7 additions & 14 deletions runners/s3-benchrunner-python/benchrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def __init__(self, *args, **kwargs):

def run(self):
# kick off all tasks
futures = [self._make_request(i)
for i in range(len(self.config.tasks))]
requests = [self._make_request(i)
for i in range(len(self.config.tasks))]

# wait until all tasks are done
for future in futures:
future.result()
for request in requests:
request.finished_future.result()

def _make_request(self, task_i) -> Future:
task = self.config.tasks[task_i]
Expand Down Expand Up @@ -179,8 +179,6 @@ def _make_request(self, task_i) -> Future:
if self.config.files_on_disk:
recv_filepath = task.key

future: Future[None] = Future()

# completion callback sets the future as complete,
# or exits the program on error
def on_done(error: Optional[Exception],
Expand All @@ -200,20 +198,14 @@ def on_done(error: Optional[Exception],
if error_body is not None:
print(error_body)

future.set_exception(error)
else:
future.set_result(None)

self._s3_client.make_request(
return self._s3_client.make_request(
request=awscrt.http.HttpRequest(
method, path, headers, send_stream),
type=s3type,
recv_filepath=recv_filepath,
send_filepath=send_filepath,
on_done=on_done)

return future


class Boto3Benchmark(Benchmark):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -289,7 +281,8 @@ def write(self, b):
f'Gb/s:{bytes_to_gigabit(bytes_per_run) / run_secs:.3f} ' +
f'Mb/s:{bytes_to_megabit(bytes_per_run) / run_secs:.3f} ' +
f'GiB/s:{bytes_to_GiB(bytes_per_run) / run_secs:.3f} ' +
f'MiB/s:{bytes_to_MiB(bytes_per_run) / run_secs:.3f}')
f'MiB/s:{bytes_to_MiB(bytes_per_run) / run_secs:.3f}',
flush=True)

# Break out if we've exceeded max_repeat_secs
app_secs = ns_to_secs(time.perf_counter_ns() - app_start_ns)
Expand Down
4 changes: 2 additions & 2 deletions scripts/fetch-git-repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
subprocess.run(cmd_args, check=True)


def try_run(cmd_args: list[str]) -> bool:
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
result = subprocess.run(cmd_args)
return result.returncode == 0

Expand Down
2 changes: 1 addition & 1 deletion scripts/install-tools-AL2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
subprocess.run(cmd_args, check=True)


Expand Down
2 changes: 1 addition & 1 deletion scripts/lint-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def run(cmd_args: list[str]):
print(f'> {subprocess.list2cmdline(cmd_args)}')
print(f'> {subprocess.list2cmdline(cmd_args)}', flush=True)
result = subprocess.run(cmd_args)
if result.returncode != 0:
exit('FAILED')
Expand Down
22 changes: 17 additions & 5 deletions scripts/run-benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import shlex
import subprocess
import sys

parser = argparse.ArgumentParser(
description='Run benchmarks with a specific runner')
Expand All @@ -22,7 +23,13 @@
'--benchmark', action='append',
help='Path to specific benchmark JSON file. ' +
'May be specified multiple times. ' +
'By default, everything in benchmarks/ is run.')
'If omitted, everything in benchmarks/ is run.')
parser.add_argument(
'--files-dir',
help='Launch runner in this directory. ' +
'Files are uploaded from and downloaded to here' +
'If omitted, CWD is used.')

args = parser.parse_args()

if args.benchmark:
Expand All @@ -40,18 +47,23 @@
if not benchmark.exists():
exit(f'benchmark not found: {str(benchmark)}')

files_dir = args.files_dir if args.files_dir else str(Path.cwd())

# split using shell-like syntax,
# in case runner-cmd has weird stuff like quotes, spaces, etc
cmd = shlex.split(args.runner_cmd)

cmd += [str(benchmark), args.bucket, args.region, str(args.throughput)]
print(f'> {subprocess.list2cmdline(cmd)}')
run = subprocess.run(cmd, text=True)
print(f'> {subprocess.list2cmdline(cmd)}', flush=True)
run = subprocess.run(cmd, text=True, cwd=files_dir)

# if runner skipped the benchmark, keep going
if run.returncode == 123:
continue

# TODO: keep going or not?
# if runner failed and we're only running 1 benchmark, exit with failure
# but if we're running multiple benchmarks, keep going
if run.returncode != 0:
exit('benchmark failed')
print('benchmark failed')
if len(benchmarks) == 1:
exit(1)

0 comments on commit a473549

Please sign in to comment.