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)]
73pub struct FetchConfig {
74 pub chunk_size: usize,
75 pub strategy: ConcurrencyStrategy,
76}
77
78impl FetchConfig {
79 pub fn random_access() -> Self {
87 Self {
88 chunk_size: get_random_access_chunk_size(),
89 strategy: ConcurrencyStrategy::BytesBased,
90 }
91 }
92
93 pub fn streaming() -> Self {
97 Self {
98 chunk_size: get_streaming_chunk_size(),
99 strategy: ConcurrencyStrategy::Legacy,
101 }
102 }
103
104 pub fn legacy() -> Self {
107 Self {
108 chunk_size: get_download_chunk_size(),
109 strategy: ConcurrencyStrategy::Legacy,
110 }
111 }
112}