Trung QuốcYiming1997/agilePool
A golang goroutine pool with high-performance and elegance
Thành tựu nổi bật
Những danh hiệu mới nhất của dự án
#1 Repository của tuần
#1 Repository của tuần
#1 Repository của tuần
🏊 agilePool — Goroutine Pool hiệu năng cao cho Go với adaptive scaling
Một goroutine pool cho Go không chỉ giới hạn worker — mà tự động điều chỉnh số worker dựa trên tải thực tế.
agilePool là thư viện goroutine pool cho Go, giải quyết bài toán quản lý hàng triệu tác vụ bất đồng bộ nhỏ mà không để goroutine phát triển mất kiểm soát. Thư viện tự động điều chỉnh số worker dựa trên thống kê rate theo sliding window, hỗ trợ retry với exponential backoff, submission có context và deadline, cùng graceful shutdown — tất cả với khả năng mở rộng cấu hình qua functional options.
✨ Điểm nổi bật
- Adaptive scaler: theo dõi median rate qua histogram sliding-window, tự động spawn/scale worker theo tải thực tế, có configurable backlog decay để xử lý burst.
- Bounded workers: giới hạn số worker chạy tối đa qua
WithWorkerNumCapacity. - Unbounded task buffering: internal handoff channel (10.000 slot) + chunked linked-list buffer với backpressure qua
maxChunkLen. - Pluggable idle containers: LinkedList (FIFO), MinHeap (LRU), Slice (FIFO), RingQueue (circular buffer, O(1) Pop).
- Retryable tasks: tự động retry khi task trả về error, mặc định exponential backoff, hỗ trợ custom backoff strategy.
- Context-aware submission:
SubmitCtxhỗ trợ cooperative cancellation trước và sau khi queue. - Deadline-bound submission:
SubmitBeforebỏ qua task nếu deadline hết trước khi worker pick up. - Graceful shutdown:
Waitđợi tất cả in-flight tasks hoàn thành,Closedừng nhận task mới. - Custom logger: plug bất kỳ implementation
Printf/Printlnnào (ví dụzap.SugaredLogger).
💡 Vì sao đáng chú ý
Khác với phần lớn goroutine pool chỉ cung cấp fixed worker count, agilePool sử dụng sliding-window rate statistics để tự động điều chỉnh số worker — nghĩa là khi tải tăng, pool tự mở rộng; khi tải giảm, idle worker bị cleanup tự động theo idle timeout. Cơ chế backlog decay factor cho phép tinh chỉnh mức độ aggressive của scaler khi xử lý burst.
Cấu trúc buffer kết hợp handoff channel nhỏ + linked-list chunked giúp vừa giữ latency thấp cho task nhanh, vừa xử lý được backlog lớn mà không cấp phát quá mức. Với nhiều tùy chọn idle container (RingQueue O(1) Pop, MinHeap LRU), người dùng có thể tối ưu cho từng trường hợp sử dụng cụ thể — từ latency-sensitive đến throughput-focused.
#Go #GoroutinePool #WorkerPool #Concurrency #TiniX
Dự án tương tự
Khám phá các dự án và mô hình AI khác có sự tương đồng.
A Simplest in-memory and Distributed Storage-Agnostic Message Queue for Your Concurrent Go Program
Get up and running with Inkling, Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.