polars_io/cloud/
concurrency_config.rs1use std::sync::LazyLock;
2
3use polars_core::config;
4
5static DOWNLOAD_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
8 let v: usize = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE")
9 .as_deref()
10 .map(|x| x.parse().expect("integer"))
11 .unwrap_or(64 * 1024 * 1024);
12
13 if config::verbose() {
14 eprintln!("async download_chunk_size: {v}")
15 }
16
17 v
18});
19
20static RANDOM_ACCESS_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
21 let v = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE_RANDOM_ACCESS")
22 .as_deref()
23 .map(|x| x.parse().expect("integer"))
24 .unwrap_or(8 * 1024 * 1024);
25
26 if config::verbose() {
27 eprintln!("async download_chunk_size_random_access: {v}")
28 }
29
30 v
31});
32
33static STREAMING_CHUNK_SIZE: LazyLock<usize> = LazyLock::new(|| {
34 let v = std::env::var("POLARS_DOWNLOAD_CHUNK_SIZE_STREAMING")
35 .as_deref()
36 .map(|x| x.parse().expect("integer"))
37 .unwrap_or(32 * 1024 * 1024);
38
39 if config::verbose() {
40 eprintln!("async download_chunk_size_streaming: {v}")
41 }
42
43 v
44});
45
46pub fn get_download_chunk_size() -> usize {
47 *DOWNLOAD_CHUNK_SIZE
48}
49
50pub fn get_random_access_chunk_size() -> usize {
51 *RANDOM_ACCESS_CHUNK_SIZE
52}
53pub fn get_streaming_chunk_size() -> usize {
54 *STREAMING_CHUNK_SIZE
55}
56
57#[derive(Clone, Debug, Copy)]
59pub enum ConcurrencyStrategy {
60 Unbounded,
64 Legacy,
67 BytesBased,
70}
71
72#[derive(Clone, Copy, Debug, PartialEq, Eq)]
74pub enum PipelineWindow {
75 FollowInflight,
76 Fixed,
77}
78
79#[derive(Clone, Copy, Debug)]
80pub struct FetchConfig {
81 pub chunk_size: usize,
82 pub strategy: ConcurrencyStrategy,
83 pub pipeline_window: PipelineWindow,
84}
85
86impl FetchConfig {
87 pub fn random_access() -> Self {
95 Self {
96 chunk_size: get_random_access_chunk_size(),
97 strategy: ConcurrencyStrategy::BytesBased,
98 pipeline_window: PipelineWindow::FollowInflight,
99 }
100 }
101
102 pub fn streaming() -> Self {
106 Self {
107 chunk_size: get_streaming_chunk_size(),
108 strategy: ConcurrencyStrategy::Legacy,
110 pipeline_window: PipelineWindow::Fixed,
111 }
112 }
113
114 pub fn legacy() -> Self {
117 Self {
118 chunk_size: get_download_chunk_size(),
119 strategy: ConcurrencyStrategy::Legacy,
120 pipeline_window: PipelineWindow::Fixed,
121 }
122 }
123}