Global per-replica concurrency gate for E2B sandbox creation. Enforced across all concurrent ExecPython executions in a single node-runner process. Sized from E2B_CONCURRENCY env var (falls back to E2B_DEFAULT_CONCURRENCY).
()
| 75 | /// across all concurrent ExecPython executions in a single node-runner process. |
| 76 | /// Sized from E2B_CONCURRENCY env var (falls back to E2B_DEFAULT_CONCURRENCY). |
| 77 | fn e2b_semaphore() -> &'static Semaphore { |
| 78 | static SEM: std::sync::OnceLock<Semaphore> = std::sync::OnceLock::new(); |
| 79 | SEM.get_or_init(|| { |
| 80 | let n = std::env::var("E2B_CONCURRENCY") |
| 81 | .ok() |
| 82 | .and_then(|v| v.parse::<usize>().ok()) |
| 83 | .filter(|&n| n > 0) |
| 84 | .unwrap_or(E2B_DEFAULT_CONCURRENCY); |
| 85 | tracing::info!("ExecPython: E2B concurrency cap = {}", n); |
| 86 | Semaphore::new(n) |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | #[derive(Default)] |
| 91 | pub struct CodeNode; |