yiming1997/agilepool/skills
Claude Code and agent skill by yiming1997/agilepool
- community
Checking that the SKILL.md file is still in the repository.
High-performance adaptive goroutine pool for Go with auto-scaling via Little's Law, sliding-window rate statistics, chunked overflow buffer, multiple idle container backends (LinkedList/MinHeap/Slice/RingQueue), customizable spinlock, retry with exponential backoff, and context-aware submission. Use when working with the github.com/Yiming1997/agilePool/v2 codebase — adding features, fixing bugs, writing tests, or answering questions about pool internals and API usage.
Install
npx vskill@latest install yiming1997/agilepool/skillsSKILL.md
agilePool — Adaptive Goroutine Pool
Overview
Package agilepool (github.com/Yiming1997/agilePool/v2, Go 1.23.4) provides an adaptive goroutine pool that dynamically scales worker count using Little's Law. It features:
- Adaptive scaling: Median rate sampling over a sliding window →
target = submitMedian × runningWorkers / consumeMedian, with backlog-weighted boosting and exit-rate compensation. - Chunked overflow buffer: When the handoff channel is full, tasks spool into a linked-list of fixed-size chunks (4096 slots each). Soft cap at 100k total tasks; exceeding it blocks on the channel instead of growing unboundedly.
- Multiple idle containers:
LinkedListType(default FIFO),MinHeapType,SliceType,RingQueueType— pluggable via config. - Configurable locking:
muIdlelock can besync.Mutex(default) or a customspinLock(three-phase: CAS → exponential backoff → Gosched). - Task variants:
Taskinterface,TaskFunc(bare func),TaskWithRetry(exponential backoff), context-aware viaSubmitCtx, timeout viaSubmitBefore. - Panic-safe: Workers recover from panics and continue processing.
- Graceful shutdown:
Close()+Wait()pattern.
Quick Start
API Reference
Pool Creation
NewPool(nil) uses defaults (unlimited workers, LinkedListType, MutexLock).
Task Interface and Types
Submission Methods
| Method | Behavior | |
|---|---|---|
pool.Submit(task) | Enqueues task; no-op on nil. Returns void. | |
pool.TrySubmit(task) bool | Returns false if rejected (pool closed, nil task, or NONBLOCK mode queue full). | |
pool.SubmitCtx(ctx, task) | Wraps task with context; skips execution if ctx.Err() != nil at dequeue time. | |
pool.SubmitBefore(task, timeout) | Skips task if not started within timeout. |
Shutdown
Critical: Call Close() before Wait(). Calling Wait() alone blocks forever because the background goroutines never exit.
Query Methods
Logger
Configuration Options
All via functional options pattern:
WorkMode
- BLOCK (default):
Submitblocks until the task is accepted (channel or chunked buffer). - NONBLOCK:
Submitdrops the task when the handoff channel is full. UseTrySubmitto detect rejection.
IdleContainerType
| Type | Add | Pop | Best for | |
|---|---|---|---|---|
LinkedListType | O(1) | O(1) | General purpose (default) | |
MinHeapType | O(log n) | O(log n) | Ordered by lastActiveAt | |
SliceType | O(1) | O(n) | Simple, small pools | |
RingQueueType | O(1) | O(1) | High-frequency Pop; works well with SpinLock |
Common Patterns
Graceful Shutdown
Producer-Consumer
Context-Aware with Cancellation
Anti-Patterns & Pitfalls
- Don't call `Wait()` before `Close()` — the pool has background goroutines (cleaner, scaler, sampler).
Wait()withoutClose()blocks forever.
- Don't `Close()` from within a task without defer —
Close()stops the cleaner goroutine, causing idle workers to accumulate. Closing inside a task is safe but usedefer pool.Close()only at the outer scope.
- Nil `*TaskWithRetry` panics —
isNilTaskchecks*TaskWithRetry == nilbut not itsTaskfield. EnsureTaskis non-nil.
- `SubmitCtx` with `nil` context — automatically uses
context.Background(). An already-canceled context causes the task to be silently dropped.
- `GetTaskQueueLen()` is incomplete — it only reports
len(taskQueue), not the chunked overflow buffer. For true backlog, check your own metrics.
- Task closure capture — Go loop variable capture applies. Always copy:
``go for _, v := range items { v := v pool.Submit(agilepool.TaskFunc(func() error { use(v); return nil })) } ``
Testing
Tests use package agilepool_test (external test package) — import github.com/Yiming1997/agilePool/v2 and use the public API. Use testing.Short() guards for heavy benchmarks:
Internal Architecture (when modifying code)
- `pool.go`: Core Pool struct, NewPool, Submit path (channel → chunked buffer → backpressure), scaler with
scaleIfNeeded(), Close/Wait. - `config.go`:
Configstruct andWith*functional options. - `worker.go`:
worker.run()— three-phase task acquisition loop: (1) channel receive, (2) chunked buffer batch (up to 8 per lock), (3) second channel check before parking. - `task.go`:
Taskinterface,TaskFunc,TaskWithRetry(exponential backoff default:min × 2^retryNum, capped atmax). - `idle_container.go`:
IdleWorkerContainerinterface +IdleContainerTypeenum. - `idle_linkedlist.go` / `idle_heap.go` / `idle_slice.go` / `idle_ring_queue.go`: Concrete implementations.
- `histogram.go`: Fixed-bucket sliding-window histogram for rate sampling. Used by scaler to compute median submit/consume/exit rates.
- `spinlock.go`: Three-phase spin lock implementing
sync.Locker. Used formuIdlewhenWithLockType(SpinLock). - `stack_trace.go`:
Stack(skip)for panic recovery — reads source files, so not for production hot paths.
Code Modification Notes
pendingTasksis atomic — decremented inpool.done(), incremented on submit. It covers submitters blocked on the channel, giving the scaler full visibility.- Workers are pooled via
sync.Pool. Do NOTworkerPool.Put(w)when the worker is also inidleWorks— that causes dual ownership and data races. - The scaler runs every
scalerPeriod(default 10ms). It reads median rates from histograms, computes target via Little's Law with backlog-weighted boosting. taskMuprotects the chunked buffer. Workers batch-pop up to 8 tasks per lock acquisition to amortize contention.- The spinlock does NOT call into the kernel — optimal when hold times are <1µs (e.g., RingQueue index swaps). Use
MutexLockfor longer or unpredictable hold times.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/SKILL.md
Popularity
- Repository stars
- 298
- Repository forks
- 43
- 7-day trend score
- 34
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/yiming1997/agilepool/skills)