use std::sync::LazyLock;
use polars_core::config;
static DOWNLOAD_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
let v: usize = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE")
.as_deref()
.map(|x| x.parse().expect("integer"))
.unwrap_or(64 * 1024 * 1024);
if config::verbose() {
eprintln!("async download_chunk_size: {v}")
}
v
});
static RANDOM_ACCESS_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
let v = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE_RANDOM_ACCESS")
.as_deref()
.map(|x| x.parse().expect("integer"))
.unwrap_or(8 * 1024 * 1024);
if config::verbose() {
eprintln!("async download_chunk_size_random_access: {v}")
}
v
});
static STREAMING_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
let v = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE_STREAMING")
.as_deref()
.map(|x| x.parse().expect("integer"))
.unwrap_or(32 * 1024 * 1024);
if config::verbose() {
eprintln!("async download_chunk_size_streaming: {v}")
}
v
});
pub fn get_download_chunk_size() -> usize {
*DOWNLOAD_CHUNK_SIZE
}
pub fn get_random_access_chunk_size() -> usize {
*RANDOM_ACCESS_CHUNK_SIZE
}
pub fn get_streaming_chunk_size() -> usize {
*STREAMING_CHUNK_SIZE
}
#[derive(Clone, Debug, Copy)]
pub enum ConcurrencyStrategy {
Unbounded,
Legacy,
BytesBased,
}
#[derive(Clone, Copy, Debug)]
pub struct FetchConfig {
pub chunk_size: usize,
pub strategy: ConcurrencyStrategy,
}
impl FetchConfig {
pub fn random_access() -> Self {
Self {
chunk_size: get_random_access_chunk_size(),
strategy: ConcurrencyStrategy::BytesBased,
}
}
pub fn streaming() -> Self {
Self {
chunk_size: get_streaming_chunk_size(),
strategy: ConcurrencyStrategy::Legacy,
}
}
pub fn legacy() -> Self {
Self {
chunk_size: get_download_chunk_size(),
strategy: ConcurrencyStrategy::Legacy,
}
}
}