Repository navigation
Let the filesystem benchmark suite set the S3 client options (GH-1325) #1407
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
Changes from all commits
6613c40
1a1dec1
a75cdf5
bd7cd85
0cfe188
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,13 +228,29 @@ The filesystem suite transfers one S3 object through PyAthena's `S3FileSystem` ( | |
| Its operations, selected with `--transport`, are: | ||
|
|
||
| - `read`: one `read()` of the whole object from a file opened with `block_size`; PyAthena's files read it as parallel range requests of that size and hold the parts and the joined object, about twice the object's size, in memory, while s3fs's file reads it as one stream through fsspec's read-ahead cache; | ||
| - `get`: `get_file()` to a local file in the trial's temporary directory; PyAthena's reads one block at a time through a file opened with `block_size`, whose `bytes` cache requests the next block with the first read and one block at a time afterwards, and s3fs's reads parallel ranges of `chunksize` with `max_concurrency` requests at a time; | ||
| - `get`: `get_file()` to a local file in the trial's temporary directory; PyAthena's reads waves of up to `max_workers` parallel ranges of `block_size`, at most as many as the request pool runs, and writes each wave before it reads the next (#1323), and s3fs's reads parallel ranges of `chunksize` with `max_concurrency` requests at a time; | ||
| - `write`: writes through a file opened with `block_size`, which uploads the object as a multipart upload with parts of that size; PyAthena's files upload up to `max_workers` parts at a time, and s3fs's file one part at a time; | ||
| - `put`: `put_file()` from a sparse local file of the object's size, so that no disk read bounds the upload; PyAthena's uploads up to `max_workers` parts of `block_size` at a time, and s3fs's `max_concurrency` parts of `chunksize`, or one PutObject for an object below both twice `chunksize` and 5 GiB; | ||
| - `copy`: `cp_file()`, or `_cp_file()` of `AioS3FileSystem`, with parts of `block_size`; PyAthena copies an object over 5 GiB as a multipart copy with up to `max_workers` part copies at a time, and s3fs copies one over 150 MiB (`s3fs.core.MANAGED_COPY_THRESHOLD`) as a multipart copy of one part at a time; the copies of smaller objects, single CopyObject requests, are recorded as unsupported; PyAthena's copies exclude tags and annotations, which the generated objects do not have. | ||
|
|
||
| Each case sets the filesystem's `max_workers` and the S3 client's `max_pool_connections`, through the connection's `s3_config` for PyAthena, and as `max_concurrency` and `config_kwargs` for s3fs, which creates its own client from the session's credentials. | ||
| The `[filesystem]` section of `config.toml` sets the swept values, 8 and 40 workers and pools of 10 and 40 by default, and a `block_size` of 8 MiB. | ||
| Its `clients` tables name sets of other botocore `Config` options of the S3 clients, passed the same way with every API; each is a case, and a name other than `default`, the only one by default, ends the case IDs, such as `filesystem-s3-sync-put-w8-p10-required`. | ||
| The clients may not set `max_pool_connections`, which `pool_connections` sweeps. | ||
| A run takes them from its `--config`, and a fleet worker from the queue's `config.toml`, so give `jobs` and `queue` the same configuration. | ||
| For example, the upload checksum settings of #1325: | ||
|
|
||
| ```toml | ||
| [filesystem.clients.default] | ||
|
|
||
| [filesystem.clients.required] | ||
| request_checksum_calculation = "when_required" | ||
|
|
||
| [filesystem.clients.unsigned] | ||
| request_checksum_calculation = "when_required" | ||
| s3 = { payload_signing_enabled = false } | ||
| ``` | ||
|
|
||
| The suite's scales are the object sizes in bytes in `[filesystem] sizes`, not the row counts in `[scales]`: 64 MiB (small), 256 MiB (medium), 1 GiB (large), and 6 GiB (xlarge) by default. | ||
| A `get` also writes the object to the trial's temporary directory, which the parent process measures as the peak temp dir and removes; on the Amazon Linux 2023 hosts, that directory is on the tmpfs `/tmp`, so the object stays in memory outside the process's RSS. A `put` reads a sparse file, which no disk bounds. | ||
|
|
||
|
|
@@ -295,11 +311,12 @@ Its operations, selected with `--transport`, and the result each trial checks ar | |
| - `find`: `find(prefix)` of the set's listing; the keys returned; | ||
| - `info`: `info(path)` of each file, through a thread pool of the case's concurrency for the synchronous filesystem and through batches of `fsspec.asyn._run_coros_in_chunks` for the other two; the entries returned. | ||
|
|
||
| Each case sets one concurrency from `[objects] concurrency`, 8 and 40 by default: the filesystem's `max_workers` and connection pool, as in the filesystem suite, and the `batch_size` of the `aio` and s3fs operations, which is the number of files they transfer at the same time. | ||
| The synchronous `S3FileSystem` inherits fsspec's sequential loops for `cat`, `get`, `put`, `pipe`, and `copy`, so its concurrency only sizes its executor and pool; its `rm` and the other two APIs' delete in DeleteObjects requests of 1,000 keys, which no batch size affects; and `find` pages through ListObjectsV2 with every API. | ||
| Each case sets one concurrency from `[objects] concurrency`, 8 and 40 by default: the filesystem's `max_workers` and connection pool, as in the filesystem suite, and the `batch_size` of the `cat`, `get`, `put`, `pipe`, and `copy` operations of every API, which is the number of files they transfer at the same time; the synchronous `S3FileSystem` runs them concurrently since #1322. | ||
| With a concurrency of 1, `cat`, `get`, `put`, `pipe`, and `copy` transfer one object at a time, so their time per object is the latency of one call. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review 4. P3 — The concurrency-one latency statement includes bulk operations (reviewed at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and fixed in a75cdf5: the README limits the one-call latency at concurrency 1 to |
||
| `rm` deletes in DeleteObjects requests of up to 1,000 keys with every API, PyAthena's up to `max_workers` of them at once, so a set of up to 1,000 objects takes one request at any concurrency; `find` pages through ListObjectsV2 with every API. | ||
| The `aio` API awaits each operation's coroutine on the trial's event loop, whose lag is sampled; the `sync` and `s3fs` APIs call the operation on the trial's thread. | ||
| Besides the metrics of the filesystem suite, each trial records the objects per second and the process CPU time of the operation, user and system, as `cpu_seconds`. | ||
| The objects that `put`, `pipe`, and `copy` create, the copies that an `rm` trial prepares, and the local files of `get` and `put`, are removed after the check, also when the preparation or the operation failed, and a removal that fails makes the trial an error; a write of the `aio` API that a failed batch leaves running in a thread may create an object after the removal. | ||
| The objects that `put`, `pipe`, and `copy` create, the copies that an `rm` trial prepares, and the local files of `get` and `put`, are removed after the check, also when the preparation or the operation failed, and a removal that fails makes the trial an error. | ||
| `cleanup` removes the sets and any remaining trial objects. | ||
|
|
||
| ```bash | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from botocore.config import Config | ||
| from botocore.exceptions import BotoCoreError | ||
|
|
||
| FLAT_COLUMNS = ( | ||
| '"timestamp", country_code, url, project, file.filename AS filename, ' | ||
| "file.version AS version, file.type AS file_type, details.python AS python, " | ||
|
|
@@ -56,6 +59,11 @@ def identifier(value: str) -> str: | |
| return value | ||
|
|
||
|
|
||
| # The botocore checksum settings of an S3 client and their values. | ||
| CHECKSUM_SETTINGS = ("request_checksum_calculation", "response_checksum_validation") | ||
| CHECKSUM_VALUES = ("when_supported", "when_required") | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Settings: | ||
| region: str = "us-west-2" | ||
|
|
@@ -82,6 +90,10 @@ class Settings: | |
| filesystem_block_size: int = 8 * 2**20 | ||
| filesystem_max_workers: list[int] = field(default_factory=lambda: [8, 40]) | ||
| filesystem_pool_connections: list[int] = field(default_factory=lambda: [10, 40]) | ||
| # Named sets of botocore Config options of the S3 clients of the filesystem suite, | ||
| # such as its checksum settings; each is a case, and those other than "default" | ||
| # add their names to the case IDs. | ||
| filesystem_clients: dict[str, dict[str, Any]] = field(default_factory=lambda: {"default": {}}) | ||
| # The objects suite: object counts by scale name, the size of each object, the | ||
| # keys of the listing set per object, and the swept concurrency, which is the | ||
| # filesystem's max_workers and connection pool and the batch size of its operations. | ||
|
|
@@ -139,6 +151,27 @@ def __post_init__(self) -> None: | |
| values = getattr(self, name) | ||
| if not values or any(type(v) is not int or v < 1 for v in values): | ||
| raise ValueError(f"Invalid {name}") | ||
| if not self.filesystem_clients: | ||
| raise ValueError("At least one filesystem client is required") | ||
| for name, options in self.filesystem_clients.items(): | ||
| identifier(name) | ||
| if not isinstance(options, dict): | ||
| raise ValueError("Filesystem clients must be tables of botocore Config options") | ||
| if "max_pool_connections" in options: | ||
| raise ValueError("pool_connections sets the connection pool of the clients") | ||
| try: | ||
| # Checks the names of the options; creating a client, which also checks | ||
| # values, would read the AWS configuration of the environment. | ||
| Config(**options) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent follow-up review (relayed): Codex CLI Covered: the four repairs, the filesystem and objects call paths, the connection's 1. P2 — Configuration validation depends on AWS configuration and can access the network (reviewed at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and fixed in bd7cd85: loading no longer creates a client. |
||
| except (TypeError, BotoCoreError) as e: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent second follow-up, finding 2. P3 — Constructor validation exceptions escape normalization (reviewed at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and fixed in 0cfe188: |
||
| raise ValueError(f"Invalid options of the filesystem client {name}: {e}") from e | ||
| # botocore checks the values of the checksum settings only when it creates | ||
| # a client, which a trial would fail at. | ||
| for key in CHECKSUM_SETTINGS: | ||
| value = options.get(key, CHECKSUM_VALUES[0]) | ||
| # botocore lowercases the value before it checks it. | ||
| if not isinstance(value, str) or value.lower() not in CHECKSUM_VALUES: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent second follow-up review (relayed): Codex CLI Covered: the repair diff, settings loading, the locked botocore 1.43.102's validation, the filesystem consumers, the changed and neighboring tests. Both side effects of the previous validation are removed. Result: FINDINGS (2). 1. P2 — Valid checksum values are rejected (reviewed at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and fixed in 0cfe188: the value is compared in lowercase, as botocore compares it, and the stored option keeps its case. A value that is not a string is rejected.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent third follow-up review (relayed): Codex CLI Covered: the repair diff, the surrounding configuration and client plumbing, the locked botocore 1.43.102 source, the changed tests. Checksum casing matches botocore's normalization without changing the supplied options; Result: CLEAN. |
||
| raise ValueError(f"Invalid {key} of the filesystem client {name}") | ||
| if not self.objects_counts: | ||
| raise ValueError("Objects counts must name at least one scale") | ||
| for name, count in self.objects_counts.items(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,12 +191,28 @@ def missing_api_reason(case: Case) -> str | None: | |
| return None | ||
|
|
||
|
|
||
| def client_options(settings: Settings, case: Case) -> dict[str, Any]: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Self-review round one (implementation behavior): base Covered: FINDINGS, repaired: a run reads the client sets from its own configuration, and a fleet worker from the queue's |
||
| """Return the botocore Config options of the S3 clients of a case. | ||
|
|
||
| Args: | ||
| settings: Configuration with the named client options of the filesystem suite. | ||
| case: Case of the filesystem or objects suite. | ||
|
|
||
| Returns: | ||
| The case's connection pool size, with the options of its client in the | ||
| filesystem suite; the objects suite's clients take no other option. | ||
| """ | ||
| options = settings.filesystem_clients[case.client] if case.suite == "filesystem" else {} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed): Codex CLI Covered: configuration loading and validation; case IDs and matrix defaults; result serialization, reporting, and resume keys; fleet jobs, queues, and worker configuration; 1. P2 — Filesystem client settings leak into objects-suite s3fs runs (reviewed at
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified and fixed in a75cdf5: |
||
| return {"max_pool_connections": case.pool_connections, **options} | ||
|
|
||
|
|
||
| def filesystem(settings: Settings, case: Case, session_: Any, connection: Any) -> Any: | ||
| """Create the filesystem of a case, with its S3 client. | ||
|
|
||
| The PyAthena filesystems share the connection's S3 client, whose | ||
| connection pool has the case's size. s3fs creates its own client from the | ||
| session's credentials, with a connection pool of the same size, and takes | ||
| connection pool has the case's size and which takes the options of the | ||
| case's client (see :func:`client_options`). s3fs creates its own client | ||
| from the session's credentials, with the same pool size and options, and takes | ||
| the case's ``max_workers`` as its ``max_concurrency``, the number of | ||
| parallel range requests of ``get_file()`` and parts of ``put_file()``. | ||
| Its client is connected here, as the PyAthena filesystems take the | ||
|
|
@@ -230,7 +246,7 @@ def filesystem(settings: Settings, case: Case, session_: Any, connection: Any) - | |
| config_kwargs={ | ||
| "connect_timeout": 10, | ||
| "read_timeout": 60, | ||
| "max_pool_connections": case.pool_connections, | ||
| **client_options(settings, case), | ||
| }, | ||
| max_concurrency=case.max_workers, | ||
| skip_instance_cache=True, | ||
|
|
@@ -287,7 +303,7 @@ async def run_filesystem( | |
| region_name=settings.region, | ||
| work_group=settings.workgroup, | ||
| config=Config(connect_timeout=10, read_timeout=60), | ||
| s3_config=Config(max_pool_connections=case.pool_connections), | ||
| s3_config=Config(**client_options(settings, case)), | ||
| ) | ||
| fs = filesystem(settings, case, session_, connection) | ||
| local = temp_dir / "object" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,10 +42,18 @@ def test_identifier_rejects_sql_and_path_syntax(value): | |
| {"objects_listing_keys_per_object": 0}, | ||
| {"objects_size": 5 * 2**30 + 1}, | ||
| {"objects_concurrency": []}, | ||
| {"filesystem_clients": {}}, | ||
| {"filesystem_clients": {"Required": {}}}, | ||
| {"filesystem_clients": {"required": "when_required"}}, | ||
| {"filesystem_clients": {"required": {"checksum": "when_required"}}}, | ||
| {"filesystem_clients": {"required": {"request_checksum_calculation": "when_requred"}}}, | ||
| {"filesystem_clients": {"required": {"response_checksum_validation": "never"}}}, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent second follow-up, test note. The added
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed; addressed in 0cfe188 with |
||
| {"filesystem_clients": {"retries": {"retries": {"mode": "standrad"}}}}, | ||
| {"filesystem_clients": {"pool": {"max_pool_connections": 40}}}, | ||
| ], | ||
| ) | ||
| def test_invalid_measurement_settings(changes): | ||
| with pytest.raises(ValueError, match=r"Invalid|positive|must"): | ||
| with pytest.raises(ValueError, match=r"Invalid|positive|must|required|sets"): | ||
| replace(Settings(), **changes) | ||
|
|
||
|
|
||
|
|
@@ -131,6 +139,55 @@ def test_filesystem_matrix_sweeps_workers_and_pools_for_each_api_and_operation() | |
| assert matrix(settings, "filesystem", "nested") == [] | ||
|
|
||
|
|
||
| def test_filesystem_clients_add_named_cases(tmp_path): | ||
| # GH-1325: each named set of S3 client options is a case of every operation, API, | ||
| # and pool; the default client keeps the IDs without a client name. | ||
| config = tmp_path / "config.toml" | ||
| config.write_text( | ||
| "[filesystem]\nmax_workers = [8]\npool_connections = [10]\n" | ||
| "[filesystem.clients.default]\n" | ||
| '[filesystem.clients.required]\nrequest_checksum_calculation = "when_required"\n' | ||
| "[filesystem.clients.unsigned]\n" | ||
| 'request_checksum_calculation = "when_required"\n' | ||
| "s3 = { payload_signing_enabled = false }\n" | ||
| ) | ||
| settings = Settings.load(config) | ||
| assert settings.filesystem_clients == { | ||
| "default": {}, | ||
| "required": {"request_checksum_calculation": "when_required"}, | ||
| "unsigned": { | ||
| "request_checksum_calculation": "when_required", | ||
| "s3": {"payload_signing_enabled": False}, | ||
| }, | ||
| } | ||
| cases = matrix(settings, "filesystem", "flat") | ||
| assert len(cases) == 5 * 3 * 3 | ||
| assert { | ||
| "filesystem-s3-sync-put-w8-p10", | ||
| "filesystem-s3-aio-put-w8-p10-required", | ||
| "filesystem-s3-s3fs-write-w8-p10-unsigned", | ||
| } <= {c.id for c in cases} | ||
| assert len({c.id for c in cases}) == len(cases) | ||
|
|
||
|
|
||
| def test_filesystem_clients_are_checked_without_the_aws_configuration(monkeypatch): | ||
| # GH-1325: the options are checked without creating a client, which would read | ||
| # the AWS configuration of the environment and change nested options in place; | ||
| # botocore accepts the checksum values in any case. | ||
| monkeypatch.setenv("AWS_PROFILE", "missing") | ||
| clients = { | ||
| "required": { | ||
| "request_checksum_calculation": "WHEN_REQUIRED", | ||
| "retries": {"max_attempts": 2}, | ||
| } | ||
| } | ||
| settings = Settings(filesystem_clients=clients) | ||
| assert settings.filesystem_clients["required"] == { | ||
| "request_checksum_calculation": "WHEN_REQUIRED", | ||
| "retries": {"max_attempts": 2}, | ||
| } | ||
|
|
||
|
|
||
| def test_filesystem_section_is_loaded_with_its_own_scales(tmp_path): | ||
| config = tmp_path / "config.toml" | ||
| config.write_text( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review round two (claims, compatibility, operations): base
13031a5daf4d2afd66eba33c50089024ec48314e, head1a1dec13333f753ef98950b6f907af7883cb6716.Claims checked:
defaultset, whose IDs carry no suffix; the existing ID tests pass unchanged.max_workersas its default batch size":S3FileSystem._batch_limit()at master; so the objects suite measured concurrent synchronous batches already, and passingbatch_sizechanges no measured value.getdescription matchesS3File._download().Compatibility: older result records without
clientload with the default; a configuration withoutclientsbehaves as before. Operator: none at runtime; the clients only change what a configured run measures.Evidence:
just benchmark testin the three environments; mutants per change. No AWS run. FINDINGS: none beyond round one.