zarrnii.benchmark
Benchmarking API for evaluating OME-Zarr chunking/sharding choices and Dask scheduler setups.
Benchmarking tool for OME-Zarr chunking, sharding, and Dask configuration.
This module provides utilities to help users choose optimal chunking, sharding, and Dask scheduler settings for their workloads. It measures wall-clock time, peak memory, and CPU efficiency for the key operations:
- Create a synthetic Dask array of configurable shape / dtype.
- Write the array to an OME-Zarr store (via :func:
zarrnii.save_ngff_image). - Read the array back from the store.
Typical usage
Run from the command line::
zarrnii-benchmark --shape 64 256 256 \
--chunks 32,32,32 64,64,64 \
--shards none 64,64,64 \
--dask-configs threads:4 distributed:4:2 \
--output-dir ./bench_results
Or use the Python API::
from zarrnii.benchmark import BenchmarkSuite
suite = BenchmarkSuite(
shape=(64, 256, 256),
dtype="float32",
chunk_shapes=[(32, 32, 32), (64, 64, 64)],
dask_configs=[{"scheduler": "threads", "n_threads": 4}],
output_dir="./bench_results",
)
results_df = suite.run()
suite.generate_report(results_df)
Classes
zarrnii.benchmark.DaskConfig(scheduler='threads', n_threads=4, threads_per_worker=2, label='')
dataclass
Specification for a Dask scheduler setup.
Attributes:
-
scheduler(str) –"threads"for the built-in threaded scheduler or"distributed"for adask.distributed.LocalCluster. -
n_threads(int) –Total number of threads/cores available. For the
"threads"scheduler this is passed directly asnum_workers. For"distributed"it is used together with threads_per_worker to derive the worker count. -
threads_per_worker(int) –Threads allocated to each distributed worker. Ignored when scheduler is
"threads". -
label(str) –Human-readable identifier used in reports. Auto-generated when not provided.
zarrnii.benchmark.BenchmarkConfig(shape, dtype, chunk_shape, shard_shape, dask_config)
dataclass
Full configuration for one benchmark scenario.
Attributes:
-
shape(Tuple[int, ...]) –Spatial shape of the synthetic array, e.g.
(64, 256, 256). -
dtype(str) –NumPy dtype string, e.g.
"float32". -
chunk_shape(Tuple[int, ...]) –Zarr chunk shape.
-
shard_shape(Optional[Tuple[int, ...]]) –Zarr shard shape (
Nonedisables sharding). -
dask_config(DaskConfig) –Dask scheduler configuration.
Attributes
zarrnii.benchmark.BenchmarkConfig.label
property
Short human-readable identifier for this config.
zarrnii.benchmark.BenchmarkResult(config, repetition, write_wall_s=0.0, read_wall_s=0.0, write_cpu_s=0.0, read_cpu_s=0.0, peak_memory_mb=0.0, error='')
dataclass
Timing and resource metrics for one benchmark run.
Attributes:
-
config(BenchmarkConfig) –The configuration that produced this result.
-
repetition(int) –0-based repetition index.
-
write_wall_s(float) –Wall-clock seconds for the OME-Zarr write.
-
read_wall_s(float) –Wall-clock seconds for the OME-Zarr read-back.
-
write_cpu_s(float) –User+system CPU seconds consumed during write.
-
read_cpu_s(float) –User+system CPU seconds consumed during read.
-
peak_memory_mb(float) –Peak RSS memory in megabytes during the run.
-
error(str) –Non-empty string when the run raised an exception.
Attributes
zarrnii.benchmark.BenchmarkResult.total_wall_s
property
Total wall time (write + read).
zarrnii.benchmark.BenchmarkResult.write_cpu_efficiency
property
CPU efficiency during write (cpu_s / wall_s / n_threads).
zarrnii.benchmark.BenchmarkResult.read_cpu_efficiency
property
CPU efficiency during read (cpu_s / wall_s / n_threads).
Functions
zarrnii.benchmark.BenchmarkResult.to_dict()
Serialise to a flat dictionary suitable for CSV / pandas.
Source code in zarrnii/benchmark.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
zarrnii.benchmark.BenchmarkSuite(shape=(64, 256, 256), dtype='float32', chunk_shapes=None, shard_shapes=None, dask_configs=None, n_reps=3, output_dir='.', tmp_dir=None)
Orchestrate a set of ZarrNii read/write benchmarks.
Parameters
shape:
Spatial shape of the synthetic 3-D array, e.g. (64, 256, 256).
dtype:
NumPy dtype string, e.g. "float32".
chunk_shapes:
List of chunk shapes to sweep.
shard_shapes:
List of shard shapes (use [None] to disable sharding).
dask_configs:
List of :class:DaskConfig objects (or plain dicts with keys
scheduler, n_threads, threads_per_worker).
n_reps:
Number of repetitions per configuration (results are averaged).
output_dir:
Directory where CSV results and HTML report are written. Defaults
to the current working directory.
tmp_dir:
Root directory used for the temporary OME-Zarr stores written during
benchmarking (passed as dir to :class:tempfile.TemporaryDirectory).
When None (the default) the system temporary directory is used.
Set this to a directory on a different filesystem (e.g. a network
mount) to measure I/O performance on that filesystem.
Examples
from zarrnii.benchmark import BenchmarkSuite, DaskConfig suite = BenchmarkSuite( ... shape=(32, 128, 128), ... dtype="float32", ... chunk_shapes=[(16, 64, 64), (32, 128, 128)], ... dask_configs=[DaskConfig(scheduler="threads", n_threads=4)], ... n_reps=1, ... output_dir="/tmp/bench", ... ) df = suite.run() suite.generate_report(df)
Source code in zarrnii/benchmark.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
Functions
zarrnii.benchmark.BenchmarkSuite.run()
Run all benchmark configurations and return a :class:pandas.DataFrame.
Returns
pandas.DataFrame
One row per (configuration, repetition) with timing and resource
columns. See :class:BenchmarkResult for column descriptions.
Source code in zarrnii/benchmark.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
zarrnii.benchmark.BenchmarkSuite.generate_report(df)
Write CSV and HTML summary reports to :attr:output_dir.
Parameters
df:
DataFrame returned by :meth:run.
Source code in zarrnii/benchmark.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
Functions
zarrnii.benchmark.benchmark_cli(argv=None)
Entry point for the zarrnii-benchmark command-line tool.
Parameters
argv:
Argument list (uses sys.argv[1:] when None).
Source code in zarrnii/benchmark.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 | |