-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): balance chunk/codec concurrency internally and add configurat…
…ion/concurrency docs (#42) * (feat): balance chunk/codec concurrency internally * (docs): add configuration and concurrency sections * (fix): address config/concurrency comments * (fix): move `concurrency_chunks_and_codec` into trait * (fix): change use of "async.concurrency" to `chunk_concurrent_maximum` * (fix): typo
- Loading branch information
Showing
4 changed files
with
173 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use pyo3::{exceptions::PyRuntimeError, PyErr, PyResult}; | ||
use zarrs::array::{ | ||
codec::CodecOptions, concurrency::calc_concurrency_outer_inner, ArrayCodecTraits, | ||
RecommendedConcurrency, | ||
}; | ||
|
||
use crate::{chunk_item::ChunksItem, CodecPipelineImpl}; | ||
|
||
pub trait ChunkConcurrentLimitAndCodecOptions { | ||
fn get_chunk_concurrent_limit_and_codec_options( | ||
&self, | ||
codec_pipeline_impl: &CodecPipelineImpl, | ||
) -> PyResult<Option<(usize, CodecOptions)>>; | ||
} | ||
|
||
impl<T> ChunkConcurrentLimitAndCodecOptions for Vec<T> | ||
where | ||
T: ChunksItem, | ||
{ | ||
fn get_chunk_concurrent_limit_and_codec_options( | ||
&self, | ||
codec_pipeline_impl: &CodecPipelineImpl, | ||
) -> PyResult<Option<(usize, CodecOptions)>> { | ||
let num_chunks = self.len(); | ||
let Some(chunk_descriptions0) = self.first() else { | ||
return Ok(None); | ||
}; | ||
let chunk_representation = chunk_descriptions0.representation(); | ||
|
||
let codec_concurrency = codec_pipeline_impl | ||
.codec_chain | ||
.recommended_concurrency(chunk_representation) | ||
.map_err(|err| PyErr::new::<PyRuntimeError, _>(err.to_string()))?; | ||
|
||
let min_concurrent_chunks = | ||
std::cmp::min(codec_pipeline_impl.chunk_concurrent_minimum, num_chunks); | ||
let max_concurrent_chunks = | ||
std::cmp::max(codec_pipeline_impl.chunk_concurrent_maximum, num_chunks); | ||
let (chunk_concurrent_limit, codec_concurrent_limit) = calc_concurrency_outer_inner( | ||
codec_pipeline_impl.num_threads, | ||
&RecommendedConcurrency::new(min_concurrent_chunks..max_concurrent_chunks), | ||
&codec_concurrency, | ||
); | ||
let codec_options = codec_pipeline_impl | ||
.codec_options | ||
.into_builder() | ||
.concurrent_target(codec_concurrent_limit) | ||
.build(); | ||
Ok(Some((chunk_concurrent_limit, codec_options))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters