Skip to content

Commit

Permalink
naming tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Oct 18, 2023
1 parent 4446e96 commit 1406792
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
20 changes: 10 additions & 10 deletions runners/s3-benchrunner-python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import time

from runner import (
Benchmark,
BenchmarkConfig,
BenchmarkRunner,
bytes_to_MiB,
bytes_to_GiB,
bytes_to_megabit,
bytes_to_gigabit,
ns_to_secs,
)
from runner.boto3 import Boto3Benchmark
from runner.cli import CliBenchmark
from runner.crt import CrtBenchmark
from runner.boto3 import Boto3BenchmarkRunner
from runner.cli import CliBenchmarkRunner
from runner.crt import CrtBenchmarkRunner

PARSER = argparse.ArgumentParser(
description='Python benchmark runner. Pick which S3 library to use.')
Expand All @@ -26,14 +26,14 @@
PARSER.add_argument('--verbose', action='store_true')


def create_runner_for_lib(lib: str, config: BenchmarkConfig) -> Benchmark:
def create_runner_for_lib(lib: str, config: BenchmarkConfig) -> BenchmarkRunner:
"""Factory function. Create appropriate subclass, given the lib."""
if lib == 'crt':
return CrtBenchmark(config)
return CrtBenchmarkRunner(config)
if lib == 'boto3-python':
return Boto3Benchmark(config)
return Boto3BenchmarkRunner(config)
if lib.startswith('cli-'):
return CliBenchmark(config, use_crt=lib.endswith('crt'))
return CliBenchmarkRunner(config, use_crt=lib.endswith('crt'))
else:
raise ValueError(f'Unknown lib: {lib}')

Expand All @@ -44,7 +44,7 @@ def create_runner_for_lib(lib: str, config: BenchmarkConfig) -> Benchmark:
args.TARGET_THROUGHPUT, args.verbose)

# create appropriate benchmark runner for given library
benchmark = create_runner_for_lib(args.LIB, config)
runner = create_runner_for_lib(args.LIB, config)

bytes_per_run = config.bytes_per_run()

Expand All @@ -53,7 +53,7 @@ def create_runner_for_lib(lib: str, config: BenchmarkConfig) -> Benchmark:
for run_i in range(config.max_repeat_count):
run_start_ns = time.perf_counter_ns()

benchmark.run()
runner.run()

run_secs = ns_to_secs(time.perf_counter_ns() - run_start_ns)
print(f'Run:{run_i+1} ' +
Expand Down
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-python/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def bytes_per_run(self) -> int:
return sum([task.size for task in self.tasks])


class Benchmark:
class BenchmarkRunner:
"""Base class for runnable benchmark"""

def __init__(self, config: BenchmarkConfig):
Expand Down
6 changes: 3 additions & 3 deletions runners/s3-benchrunner-python/runner/boto3.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import boto3 # type: ignore
from concurrent.futures import ThreadPoolExecutor

from runner import Benchmark, BenchmarkConfig
from runner import BenchmarkConfig, BenchmarkRunner


class Boto3Benchmark(Benchmark):
"""Runnable benchmark using boto3.client('s3')"""
class Boto3BenchmarkRunner(BenchmarkRunner):
"""Benchmark runner using boto3.client('s3')"""

def __init__(self, config: BenchmarkConfig):
super().__init__(config)
Expand Down
6 changes: 4 additions & 2 deletions runners/s3-benchrunner-python/runner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from typing import Optional, Tuple

from runner import (
Benchmark,
BenchmarkRunner,
BenchmarkConfig,
exit_with_error,
exit_with_skip_code,
)


class CliBenchmark(Benchmark):
class CliBenchmarkRunner(BenchmarkRunner):
"""Benchmark runner using AWS CLI"""

def __init__(self, config: BenchmarkConfig, use_crt: bool):
super().__init__(config)
self.use_crt = use_crt
Expand Down
11 changes: 5 additions & 6 deletions runners/s3-benchrunner-python/runner/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import awscrt.http # type: ignore
import awscrt.io # type: ignore
import awscrt.s3 # type: ignore
from concurrent.futures import Future
from typing import Optional, Tuple

from runner import Benchmark, BenchmarkConfig
from runner import BenchmarkConfig, BenchmarkRunner


class CrtBenchmark(Benchmark):
"""Runnable benchmark using aws-crt-python's S3Client"""
class CrtBenchmarkRunner(BenchmarkRunner):
"""Benchmark runner using aws-crt-python's S3Client"""

def __init__(self, config: BenchmarkConfig):
super().__init__(config)
Expand Down Expand Up @@ -39,7 +38,7 @@ def run(self):
for request in requests:
request.finished_future.result()

def _make_request(self, task_i) -> Future:
def _make_request(self, task_i) -> awscrt.s3.S3Request:
task = self.config.tasks[task_i]

headers = awscrt.http.HttpHeaders()
Expand Down Expand Up @@ -80,7 +79,7 @@ def _make_request(self, task_i) -> Future:

# completion callback sets the future as complete,
# or exits the program on error
def on_done(error: Optional[Exception],
def on_done(error: Optional[BaseException],
error_headers: Optional[list[Tuple[str, str]]],
error_body: Optional[bytes],
**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion runners/s3-benchrunner-python/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def fetch_and_install(url: str,

# create virtual environment (if necessary) awscli from Github
# doesn't interfere with system installation of awscli
venv_dir = work_dir.joinpath('.venv')
venv_dir = work_dir.joinpath('venv')
venv_python = str(venv_dir.joinpath('bin/python3'))
if not venv_dir.exists():
run([sys.executable, '-m', 'venv', str(venv_dir)])
Expand Down

0 comments on commit 1406792

Please sign in to comment.