pub struct ConcurrentBatchProcessor {
config: BatchConfig,
memory_manager: Arc<GlobalMemoryManager>,
task_queue: Arc<Mutex<VecDeque<BatchTask>>>,
concurrency_limiter: Arc<Semaphore>,
stats: Arc<RwLock<BatchProcessingStats>>,
next_task_id: Arc<Mutex<u64>>,
}Expand description
并发批处理器
Fields§
§config: BatchConfig§memory_manager: Arc<GlobalMemoryManager>§task_queue: Arc<Mutex<VecDeque<BatchTask>>>任务队列(按优先级排序)
concurrency_limiter: Arc<Semaphore>信号量控制并发数
stats: Arc<RwLock<BatchProcessingStats>>统计信息
next_task_id: Arc<Mutex<u64>>任务ID计数器
Implementations§
Source§impl ConcurrentBatchProcessor
impl ConcurrentBatchProcessor
Sourcepub fn new(
config: BatchConfig,
memory_manager: Arc<GlobalMemoryManager>,
) -> Self
pub fn new( config: BatchConfig, memory_manager: Arc<GlobalMemoryManager>, ) -> Self
创建新的并发批处理器
Sourcepub async fn submit_batch(
&self,
texts: Vec<String>,
priority: Priority,
) -> TranslationResult<u64>
pub async fn submit_batch( &self, texts: Vec<String>, priority: Priority, ) -> TranslationResult<u64>
提交批处理任务
Sourcepub async fn process_queue<F, Fut>(
&self,
translation_fn: F,
) -> TranslationResult<Vec<BatchResult>>
pub async fn process_queue<F, Fut>( &self, translation_fn: F, ) -> TranslationResult<Vec<BatchResult>>
并行处理批次队列
Sourceasync fn worker_loop<F, Fut>(&self, translation_fn: F) -> Vec<BatchResult>
async fn worker_loop<F, Fut>(&self, translation_fn: F) -> Vec<BatchResult>
工作线程循环
Sourceasync fn process_single_task<F, Fut>(
&self,
task: BatchTask,
translation_fn: &F,
) -> BatchResult
async fn process_single_task<F, Fut>( &self, task: BatchTask, translation_fn: &F, ) -> BatchResult
处理单个任务
Sourcefn clone_for_worker(&self) -> Self
fn clone_for_worker(&self) -> Self
为工作线程创建克隆(共享状态)
Sourcepub async fn get_stats(&self) -> BatchProcessingStats
pub async fn get_stats(&self) -> BatchProcessingStats
获取处理统计信息
Sourcepub fn get_queue_status(&self) -> QueueStatus
pub fn get_queue_status(&self) -> QueueStatus
获取队列状态
Sourcepub fn clear_queue(&self) -> usize
pub fn clear_queue(&self) -> usize
清空队列
Auto Trait Implementations§
impl Freeze for ConcurrentBatchProcessor
impl !RefUnwindSafe for ConcurrentBatchProcessor
impl Send for ConcurrentBatchProcessor
impl Sync for ConcurrentBatchProcessor
impl Unpin for ConcurrentBatchProcessor
impl !UnwindSafe for ConcurrentBatchProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more