1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2026 vectorless developers
// SPDX-License-Identifier: Apache-2.0
//! Concurrency control for LLM API calls.
//!
//! This module provides rate limiting and concurrency control to prevent
//! overwhelming LLM API endpoints:
//!
//! - **Rate Limiter** — Token bucket algorithm to limit requests per time period
//! - **Concurrency Controller** — Combined semaphore + rate limiter
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ LlmClient │
//! │ │
//! │ complete() ──▶ [Rate Limiter] ──▶ [Semaphore] ──▶ API Call │
//! │ │ │ │
//! │ 令牌桶限制 并发数限制 │
//! │ │
//! │ ┌─────────────────────────────────────────────────────────┐ │
//! │ │ ConcurrencyController │ │
//! │ │ │ │
//! │ │ ┌─────────────┐ ┌─────────────┐ │ │
//! │ │ │RateLimiter │ │ Semaphore │ │ │
//! │ │ │(governor) │ │(tokio) │ │ │
//! │ │ └─────────────┘ └─────────────┘ │ │
//! │ └─────────────────────────────────────────────────────────┘ │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Example
//!
//! ```rust
//! use vectorless::throttle::{ConcurrencyController, ConcurrencyConfig};
//!
//! # #[tokio::main]
//! # async fn main() {
//! // Create with default configuration
//! let controller = ConcurrencyController::with_defaults();
//!
//! // Or customize
//! let config = ConcurrencyConfig::new()
//! .with_max_concurrent_requests(20)
//! .with_requests_per_minute(1000);
//! let controller = ConcurrencyController::new(config);
//!
//! // Before making an API call
//! let permit = controller.acquire().await;
//!
//! // Make the API call...
//! // Permit is automatically released when dropped
//! # }
//! ```
pub use ConcurrencyConfig;
pub use ConcurrencyController;
pub use RateLimiter;