Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor benchmark CLI #273

Merged
merged 24 commits into from
Jul 28, 2023
Merged

Refactor benchmark CLI #273

merged 24 commits into from
Jul 28, 2023

Conversation

popematt
Copy link
Contributor

@popematt popematt commented Jul 12, 2023

Issue #, if available:

Description of changes:

This is still a WIP, but the CLI is usable with BenchmarkSpecs.

Still to-do are some more documentation, updating the benchmark cli tests, and some general double-checking of things, but you can start taking a look at it or even try it out yourself right now!

Example:

❯ python3 ./amazon/ionbenchmark/ion_benchmark_cli.py run tests/benchmark_sample_data/sample_spec/spec.ion
╒═══════════════════════════════════════════════════════╤════════════════╤════════════════╤═════════════════╤════════════════════════╕
│ name                                                  │   file_size(B) │   time_min(ns) │   time_mean(ns) │   memory_usage_peak(B) │
╞═══════════════════════════════════════════════════════╪════════════════╪════════════════╪═════════════════╪════════════════════════╡
│ (cbor,loads,cat.cbor)                                 │            131 │            458 │             505 │                   1200 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (cbor2,loads,cat.cbor)                                │            131 │           1416 │            1504 │                   1467 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (json,loads,cat.json)                                 │            178 │           1750 │            1810 │                   3157 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (ujson,loads,cat.json)                                │            178 │            541 │             571 │                    736 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (ion_text,loads,cat.ion)                              │            161 │          16333 │           16773 │                  41225 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (ion_binary,loads,cat.ion)                            │            137 │          16667 │           17191 │                  36853 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ Ion Binary, pure Python impl                          │            137 │         150334 │          156203 │                  48926 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ Ion Text, pure Python impl                            │            161 │         320625 │          332027 │                  66276 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (self_describing_protobuf,loads,cat.sd_protobuf_data) │            374 │           2500 │            2905 │                  13568 │
├───────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────────────┼────────────────────────┤
│ (protobuf,loads,cat.protobuf_data)                    │             81 │            291 │             361 │                    888 │
╘═══════════════════════════════════════════════════════╧════════════════╧════════════════╧═════════════════╧════════════════════════╛

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@rmarrowstone rmarrowstone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whole this looks like a good factoring and decreases a lot of repetitive code.

amazon/ionbenchmark/report.py Outdated Show resolved Hide resolved

from amazon.ionbenchmark.benchmark_spec import BenchmarkSpec

_pypy = platform.python_implementation() == 'PyPy'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will say again: it's not clear to me that anyone is actually using this with PyPy. For the benchmarking I would comfortable saying "we don't benchmark or profile on pypy"

@popematt
Copy link
Contributor Author

@rmarrowstone What are your thoughts on testing the benchmark CLI? Can you recommend a good overall testing strategy, or shall I just try to write unit tests for the individual components and rely on the regression workflow to catch larger problems?

@rmarrowstone
Copy link
Contributor

What are your thoughts on testing the benchmark CLI? Can you recommend a good overall testing strategy, or shall I just try to write unit tests for the individual components and rely on the regression workflow to catch larger problems?

Latter sounds reasonable. For CLIs I tend to just run them and not worry too much about automated testing of the actual executable: the ROI of such isn't great imo.

@popematt popematt marked this pull request as ready for review July 25, 2023 23:06
@popematt
Copy link
Contributor Author

Alright, I've got all tests passing now, including on PyPy. The performance workflow will fail, but I'd like to address that in a followup PR to prevent the scope of this one from growing too large.

Copy link
Contributor

@rmarrowstone rmarrowstone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor-ish comments. I can't say I've read every line thoroughly. I can say that this is such an improvement over what's there that I'm inclined to merge and iterate/fix-up as needed.

Great work!!!

amazon/ionbenchmark/Format.py Outdated Show resolved Hide resolved
amazon/ionbenchmark/Format.py Outdated Show resolved Hide resolved
amazon/ionbenchmark/benchmark_spec.py Show resolved Hide resolved
if 'name' not in self:
self['name'] = f'({self.get_format()},{self.get_operation_name()},{path.basename(self.get_input_file())})'

def __missing__(self, key):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw i think you could inherit from defaultdict to do this. not sure it's any better.

"""
return self["name"]

def get_format(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using @property annotation on methods without get_ e.g:

@property
def format(self):
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... I just tried this out, and found that I was getting inconsistent behavior between PyPy and CPython, so I'd like to leave it as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to hear that. agree not to sweat it for now.

self._loader_dumper = self._get_loader_dumper()
return self._loader_dumper

def _get_loader_dumper(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to abstract the specific format. 👍

amazon/ionbenchmark/ion_benchmark_cli.py Outdated Show resolved Hide resolved
amazon/ionbenchmark/ion_benchmark_cli.py Show resolved Hide resolved
amazon/ionbenchmark/ion_load_dump.py Outdated Show resolved Hide resolved
amazon/ionbenchmark/ion_benchmark_cli.py Outdated Show resolved Hide resolved
@popematt popematt merged commit f3f1b3c into amazon-ion:master Jul 28, 2023
9 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants