reifydb_core/value/column/pool/
config.rs1use super::{Pools, thread_local::set_thread_pools};
10
11#[derive(Clone, Debug)]
13pub struct PoolConfig {
14 pub max_pool_size: usize,
16
17 pub enable_statistics: bool,
19
20 pub auto_clear_threshold: Option<usize>,
22
23 pub prewarm_capacities: Vec<usize>,
25}
26
27impl Default for PoolConfig {
28 fn default() -> Self {
29 Self {
30 max_pool_size: 16,
31 enable_statistics: cfg!(debug_assertions),
32 auto_clear_threshold: None,
33 prewarm_capacities: vec![],
34 }
35 }
36}
37
38impl PoolConfig {
39 pub fn test() -> Self {
42 Self {
43 max_pool_size: 4,
44 enable_statistics: true,
45 auto_clear_threshold: Some(100),
46 prewarm_capacities: vec![],
47 }
48 }
49
50 pub fn production() -> Self {
53 Self {
54 max_pool_size: 32,
55 enable_statistics: false,
56 auto_clear_threshold: Some(10000),
57 prewarm_capacities: vec![16, 64, 256, 1024],
58 }
59 }
60
61 pub fn development() -> Self {
64 Self {
65 max_pool_size: 16,
66 enable_statistics: true,
67 auto_clear_threshold: Some(1000),
68 prewarm_capacities: vec![16, 64],
69 }
70 }
71}
72
73pub fn init_thread_pools(config: PoolConfig) -> Pools {
75 let pools = Pools::new(config.max_pool_size);
76
77 if !config.prewarm_capacities.is_empty() {
79 }
84
85 set_thread_pools(pools.clone());
86 pools
87}
88
89pub fn init_default_thread_pools() -> Pools {
91 init_thread_pools(PoolConfig::default())
92}
93
94pub fn init_test_pools() -> Pools {
96 init_thread_pools(PoolConfig::test())
97}
98
99pub fn init_production_pools() -> Pools {
101 init_thread_pools(PoolConfig::production())
102}
103
104pub fn init_development_pools() -> Pools {
106 init_thread_pools(PoolConfig::development())
107}
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112 use crate::value::column::pool::thread_local::{clear_thread_pools, has_thread_pools};
113
114 #[test]
115 fn test_pool_config_defaults() {
116 let config = PoolConfig::default();
117 assert_eq!(config.max_pool_size, 16);
118 assert_eq!(config.enable_statistics, cfg!(debug_assertions));
119 assert_eq!(config.auto_clear_threshold, None);
120 assert!(config.prewarm_capacities.is_empty());
121 }
122
123 #[test]
124 fn test_pool_config_test() {
125 let config = PoolConfig::test();
126 assert_eq!(config.max_pool_size, 4);
127 assert!(config.enable_statistics);
128 assert_eq!(config.auto_clear_threshold, Some(100));
129 assert!(config.prewarm_capacities.is_empty());
130 }
131
132 #[test]
133 fn test_pool_config_production() {
134 let config = PoolConfig::production();
135 assert_eq!(config.max_pool_size, 32);
136 assert!(!config.enable_statistics);
137 assert_eq!(config.auto_clear_threshold, Some(10000));
138 assert_eq!(config.prewarm_capacities, vec![16, 64, 256, 1024]);
139 }
140
141 #[test]
142 fn test_init_thread_pools() {
143 clear_thread_pools();
145 assert!(!has_thread_pools());
146
147 let pools = init_test_pools();
149 assert!(has_thread_pools());
150
151 clear_thread_pools();
153 }
154
155 #[test]
156 fn test_init_variations() {
157 clear_thread_pools();
159
160 init_default_thread_pools();
161 assert!(has_thread_pools());
162 clear_thread_pools();
163
164 init_development_pools();
165 assert!(has_thread_pools());
166 clear_thread_pools();
167
168 init_production_pools();
169 assert!(has_thread_pools());
170 clear_thread_pools();
171 }
172}