takeln/resource_limits.rs
1//! Resource limits for graph execution.
2
3/// Configurable resource boundaries for graph execution.
4///
5/// Provides hard limits on concurrency, memory usage, and cardinality
6/// to prevent unbounded resource consumption in production.
7///
8/// # Defaults
9///
10/// All defaults are generous enough for typical workloads:
11/// - 64 concurrent DAG nodes
12/// - 10,000 execution history records
13/// - 10 MB max checkpoint payload
14/// - 10,000 max DAG nodes
15/// - 1,000 max sequential steps (loop protection)
16#[derive(Debug, Clone)]
17#[non_exhaustive]
18pub struct ResourceLimits {
19 /// Maximum concurrent nodes in a DAG wave (default: 64).
20 pub max_concurrent_nodes: usize,
21 /// Maximum execution history records retained in memory (default: 10,000).
22 pub max_execution_records: usize,
23 /// Maximum checkpoint payload size in bytes (default: 10 MB).
24 pub max_checkpoint_bytes: usize,
25 /// Maximum DAG nodes allowed (default: 10,000).
26 pub max_dag_nodes: usize,
27 /// Maximum sequential steps before aborting (default: 1,000).
28 /// Prevents infinite loops when conditional edges create cycles.
29 pub max_sequential_steps: usize,
30}
31
32impl Default for ResourceLimits {
33 fn default() -> Self {
34 Self {
35 max_concurrent_nodes: 64,
36 max_execution_records: 10_000,
37 max_checkpoint_bytes: 10 * 1024 * 1024,
38 max_dag_nodes: 10_000,
39 max_sequential_steps: 1_000,
40 }
41 }
42}
43
44impl ResourceLimits {
45 /// Set the maximum concurrent nodes in a DAG wave.
46 pub fn with_max_concurrent_nodes(mut self, n: usize) -> Self {
47 self.max_concurrent_nodes = n;
48 self
49 }
50
51 /// Set the maximum execution history records.
52 pub fn with_max_execution_records(mut self, n: usize) -> Self {
53 self.max_execution_records = n;
54 self
55 }
56
57 /// Set the maximum checkpoint payload size in bytes.
58 pub fn with_max_checkpoint_bytes(mut self, n: usize) -> Self {
59 self.max_checkpoint_bytes = n;
60 self
61 }
62
63 /// Set the maximum DAG nodes allowed.
64 pub fn with_max_dag_nodes(mut self, n: usize) -> Self {
65 self.max_dag_nodes = n;
66 self
67 }
68
69 /// Set the maximum sequential steps before aborting.
70 /// Prevents infinite loops when conditional edges create cycles.
71 pub fn with_max_sequential_steps(mut self, n: usize) -> Self {
72 self.max_sequential_steps = n;
73 self
74 }
75}