Skip to content

Commit c728bf5

Browse files
committed
Add new setting for worker level configuration as well to enable better system utilization and tuning for shard-based ingestion
1 parent 05f8cee commit c728bf5

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/mdio/core/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class MDIOSettings(BaseSettings):
2020
description="Number of CPUs to use for import operations",
2121
alias="MDIO__IMPORT__CPU_COUNT",
2222
)
23+
import_zarr_threads: int = Field(
24+
default=4,
25+
description="Number of Zarr threads per worker during import operations",
26+
alias="MDIO__IMPORT__ZARR_THREADS",
27+
)
2328

2429
# Grid sparsity configuration
2530
grid_sparsity_ratio_warn: float = Field(

src/mdio/segy/_workers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ def trace_worker( # noqa: PLR0913
8989
Returns:
9090
SummaryStatistics object containing statistics about the written traces.
9191
"""
92-
# Setting the zarr config to 1 thread to ensure we honor the `MDIO__IMPORT__CPU_COUNT` environment variable.
93-
# The Zarr 3 engine utilizes multiple threads. This can lead to resource contention and unpredictable memory usage.
94-
zarr_config.set({"threading.max_workers": 1})
92+
# Configure zarr threading based on MDIO__IMPORT__ZARR_THREADS setting.
93+
# With shard-aligned writes, fewer workers are used, so we allow more zarr threads per worker
94+
# to better utilize available CPU resources.
95+
settings = MDIOSettings()
96+
zarr_config.set({"threading.max_workers": settings.import_zarr_threads})
9597

9698
region_slices = tuple(region.values())
9799
local_grid_map = grid_map[region_slices[:-1]] # minus last (vertical) axis

tests/unit/test_environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class TestEnvironment:
1616
[
1717
("MDIO__EXPORT__CPU_COUNT", "8", "export_cpus", 8),
1818
("MDIO__IMPORT__CPU_COUNT", "4", "import_cpus", 4),
19+
("MDIO__IMPORT__ZARR_THREADS", "8", "import_zarr_threads", 8),
1920
("MDIO__GRID__SPARSITY_RATIO_WARN", "3.5", "grid_sparsity_ratio_warn", 3.5),
2021
("MDIO__GRID__SPARSITY_RATIO_LIMIT", "15.0", "grid_sparsity_ratio_limit", 15.0),
2122
],

0 commit comments

Comments
 (0)