oxirs_arq/executor/
config.rs1use crate::builtin::register_builtin_functions;
6use crate::extensions::ExtensionRegistry;
7use std::sync::{Arc, OnceLock};
8use std::thread;
9use std::time::Duration;
10
11#[derive(Debug, Clone)]
13pub struct ExecutionContext {
14 pub timeout: Option<Duration>,
16 pub memory_limit: Option<usize>,
18 pub parallel: bool,
20 pub parallel_config: ParallelConfig,
22 pub streaming: StreamingResultConfig,
24 pub collect_stats: bool,
26 pub parallel_threshold: usize,
28 pub enable_caching: bool,
30 pub extension_registry: Arc<ExtensionRegistry>,
32}
33
34#[derive(Debug, Clone)]
36pub struct ParallelConfig {
37 pub max_threads: usize,
39 pub work_stealing: bool,
41 pub chunk_size: usize,
43 pub parallel_threshold: usize,
45 pub thread_pool_config: ThreadPoolConfig,
47 pub numa_aware: bool,
49 pub min_parallel_work: usize,
51 pub adaptive: bool,
53}
54
55#[derive(Debug, Clone)]
57pub struct ThreadPoolConfig {
58 pub stack_size: Option<usize>,
60 pub thread_priority: Option<i32>,
62 pub thread_affinity: bool,
64}
65
66#[derive(Debug, Clone)]
68pub struct StreamingResultConfig {
69 pub buffer_size: usize,
71 pub batch_size: usize,
73 pub enabled: bool,
75}
76
77static FUNCTION_REGISTRY: OnceLock<Arc<ExtensionRegistry>> = OnceLock::new();
79
80fn get_function_registry() -> &'static Arc<ExtensionRegistry> {
81 FUNCTION_REGISTRY.get_or_init(|| {
82 let registry = Arc::<ExtensionRegistry>::new(ExtensionRegistry::new());
83 register_builtin_functions(®istry).expect("Failed to register built-in functions");
84 registry
85 })
86}
87
88impl Default for ExecutionContext {
89 fn default() -> Self {
90 Self {
91 timeout: Some(Duration::from_secs(300)), memory_limit: Some(1024 * 1024 * 1024), parallel: true,
94 parallel_config: ParallelConfig::default(),
95 streaming: StreamingResultConfig::default(),
96 collect_stats: false,
97 parallel_threshold: 1000,
98 enable_caching: true,
99 extension_registry: get_function_registry().clone(),
100 }
101 }
102}
103
104impl ExecutionContext {
105 pub fn new() -> Self {
106 Self::default()
107 }
108}
109
110impl Default for ParallelConfig {
111 fn default() -> Self {
112 let num_cpus = thread::available_parallelism()
113 .map(|n| n.get())
114 .unwrap_or(4);
115
116 Self {
117 max_threads: num_cpus,
118 work_stealing: true,
119 chunk_size: 1000,
120 parallel_threshold: 10000,
121 thread_pool_config: ThreadPoolConfig::default(),
122 numa_aware: false,
123 min_parallel_work: 100,
124 adaptive: true,
125 }
126 }
127}
128
129impl Default for ThreadPoolConfig {
130 fn default() -> Self {
131 Self {
132 stack_size: Some(8 * 1024 * 1024), thread_priority: None,
134 thread_affinity: false,
135 }
136 }
137}
138
139impl Default for StreamingResultConfig {
140 fn default() -> Self {
141 Self {
142 buffer_size: 10000,
143 batch_size: 1000,
144 enabled: false,
145 }
146 }
147}