{"id":47890417,"url":"https://github.com/AshvinBambhaniya/autopool","last_synced_at":"2026-04-12T06:01:10.829Z","repository":{"id":348002184,"uuid":"1196053212","full_name":"AshvinBambhaniya/autopool","owner":"AshvinBambhaniya","description":"Zero-config, auto-scaling worker pool for Go with priority-aware scheduling, adaptive resource management, and per-task retry logic.","archived":false,"fork":false,"pushed_at":"2026-04-03T10:07:55.000Z","size":42,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T08:29:26.962Z","etag":null,"topics":["async","auto-scaling","backpressure","concurrency","golang","performance","priority-queue","retry-strategy","scheduling","worker-pool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AshvinBambhaniya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-30T10:22:28.000Z","updated_at":"2026-04-03T13:00:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/AshvinBambhaniya/autopool","commit_stats":null,"previous_names":["ashvinbambhaniya/autopool"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/AshvinBambhaniya/autopool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshvinBambhaniya%2Fautopool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshvinBambhaniya%2Fautopool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshvinBambhaniya%2Fautopool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshvinBambhaniya%2Fautopool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AshvinBambhaniya","download_url":"https://codeload.github.com/AshvinBambhaniya/autopool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshvinBambhaniya%2Fautopool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31705574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T05:11:36.334Z","status":"ssl_error","status_checked_at":"2026-04-12T05:11:27.332Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","auto-scaling","backpressure","concurrency","golang","performance","priority-queue","retry-strategy","scheduling","worker-pool"],"created_at":"2026-04-04T03:00:37.436Z","updated_at":"2026-04-12T06:01:10.822Z","avatar_url":"https://github.com/AshvinBambhaniya.png","language":"Go","funding_links":[],"categories":["Goroutines"],"sub_categories":["Search and Analytic Databases"],"readme":"# autopool: High-Performance Golang Worker Pool\r\n\r\n**Zero-config, auto-scaling worker pool for Go (Golang) with priority-aware scheduling.**\r\n\r\n`autopool` is a lightweight, high-performance library designed for efficient **goroutine management**. It manages an elastic pool of workers to process tasks asynchronously, combining dynamic **auto-scaling** with a sophisticated **priority-aware queue**. This ensures that critical tasks jump the line while background work remains resilient, memory-safe, and starvation-free.\r\n\r\n[![Go CI](https://github.com/AshvinBambhaniya/autopool/actions/workflows/go.yml/badge.svg)](https://github.com/AshvinBambhaniya/autopool/actions/workflows/go.yml)\r\n[![Go Report Card](https://goreportcard.com/badge/github.com/AshvinBambhaniya/autopool/v2)](https://goreportcard.com/report/github.com/AshvinBambhaniya/autopool/v2)\r\n[![Go Reference](https://pkg.go.dev/badge/github.com/AshvinBambhaniya/autopool/v2.svg)](https://pkg.go.dev/github.com/AshvinBambhaniya/autopool/v2)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n---\r\n\r\n## Why autopool?\r\n\r\nIn complex **Go concurrency** environments, not all tasks are created equal. While standard worker pools treat every job the same, `autopool` allows you to prioritize system-critical operations without permanently starving low-priority background jobs.\r\n\r\n- **Dynamic Scaling:** Don't waste memory on idle goroutines. `autopool` grows under load and shrinks during downtime.\r\n- **Starvation Prevention:** Our Virtual Runtime Aging model ensures even the lowest priority tasks eventually get processed.\r\n- **Zero Config:** Get started with sensible defaults, or tune every aspect of the pool's lifecycle.\r\n\r\n---\r\n\r\n## Table of Contents\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Quick Start](#quick-start)\r\n- [Configuration](#configuration)\r\n- [Per-Task Options](#per-task-options)\r\n- [Task Prioritization \u0026 Aging](#task-prioritization--aging)\r\n- [Benchmarks](#benchmarks)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n\r\n---\r\n\r\n## Features\r\n\r\n- **High Throughput:** Optimized for millions of tasks per second with minimal overhead.\r\n- **Priority-Aware Scheduling:** Support for `Critical`, `High`, `Normal`, and `Low` priority levels.\r\n- **Anti-Starvation (Aging):** Virtual Runtime model ensures low-priority tasks execute even under heavy load.\r\n- **Auto-scaling:** Spawns workers on demand and terminates idle ones automatically.\r\n- **Resource Safety:** Bounded priority queue provides natural backpressure and prevents memory exhaustion.\r\n- **Graceful Shutdown:** Ensures active tasks are drained completely before stopping.\r\n- **Panic Recovery:** Built-in recovery per worker prevents cascading pool failures.\r\n- **Smart Retries:** Per-task exponential backoff strategy for resilient processing.\r\n- **Real-time Metrics:** Deep visibility into worker counts and queue depth.\r\n\r\n## Installation\r\n\r\n```bash\r\ngo get github.com/AshvinBambhaniya/autopool/v2\r\n```\r\n\r\n## Quick Start\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"context\"\r\n\t\"fmt\"\r\n\t\"github.com/AshvinBambhaniya/autopool/v2\"\r\n\t\"time\"\r\n)\r\n\r\nfunc main() {\r\n\t// Initialize pool with custom limits\r\n\tp := autopool.New(\r\n\t\tautopool.WithMaxWorkers(10),\r\n\t\tautopool.WithQueueSize(100),\r\n\t)\r\n\r\n\t// Submit a task (defaults to PriorityNormal)\r\n\tp.Submit(func(ctx context.Context) error {\r\n\t\tfmt.Println(\"Processing task...\")\r\n\t\treturn nil\r\n\t})\r\n\r\n\t// Submit a high-priority task that jumps the line\r\n\tp.SubmitWithOptions(func(ctx context.Context) error {\r\n\t\tfmt.Println(\"Processing critical work...\")\r\n\t\treturn nil\r\n\t}, autopool.TaskOptions{Priority: autopool.PriorityHigh})\r\n\r\n\t// Graceful shutdown with timeout\r\n\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\r\n\tdefer cancel()\r\n\tp.Shutdown(ctx)\r\n}\r\n```\r\n\r\n## Configuration\r\n\r\nThe pool is highly configurable using functional options:\r\n\r\n```go\r\np := autopool.New(\r\n\tautopool.WithMinWorkers(2),         // Always keep 2 workers alive\r\n\tautopool.WithMaxWorkers(50),        // Allow scaling up to 50\r\n\tautopool.WithQueueSize(1000),       // Buffer size (Submit blocks when full)\r\n\tautopool.WithIdleTimeout(5 * time.Minute), // When to scale down\r\n\tautopool.WithPanicHandler(myPanicHandler),\r\n\tautopool.WithErrorHandler(myErrorHandler), // Handle final failures after retries\r\n)\r\n```\r\n\r\n## Per-Task Options\r\n\r\nYou can control retry behavior, timeouts, and priority for individual tasks:\r\n\r\n```go\r\nerr := p.SubmitWithOptions(func(ctx context.Context) error {\r\n    return doWork()\r\n}, autopool.TaskOptions{\r\n    Priority:   autopool.PriorityHigh,\r\n    RetryCount: 3,\r\n    RetryDelay: 500 * time.Millisecond,\r\n    Timeout:    2 * time.Second,\r\n})\r\n```\r\n\r\n## Task Prioritization \u0026 Aging\r\n\r\n`autopool` uses a **Virtual Runtime Aging** model. When a task is submitted, it is assigned a virtual score based on its priority. As time passes, the relative \"urgency\" of older tasks increases naturally. This ensures that high-priority tasks jump the line while guaranteeing that low-priority tasks are not starved indefinitely.\r\n\r\n**Supported levels:** `PriorityLow`, `PriorityNormal` (default), `PriorityHigh`, `PriorityCritical`.\r\n\r\n## Benchmarks\r\n\r\nMeasured on 12th Gen Intel(R) Core(TM) i7-12700:\r\n\r\n| Operation | Performance |\r\n| :--- | :--- |\r\n| **Queue Push** | **~52 ns/op** |\r\n| **Queue Pop** | **~204 ns/op** |\r\n| **Throughput (100k tasks)** | **~1,200,000 tasks/sec** |\r\n| **Goroutine Leaks** | **None (Verified with -race)** |\r\n\r\n## Contributing\r\n\r\nContributions to `autopool` are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\r\n\r\n1. Fork the Project\r\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\r\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\r\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\r\n5. Open a Pull Request\r\n\r\n## License\r\n\r\nDistributed under the MIT License. See [LICENSE](LICENSE) for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshvinBambhaniya%2Fautopool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAshvinBambhaniya%2Fautopool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshvinBambhaniya%2Fautopool/lists"}