{"id":42201013,"url":"https://github.com/yudhasubki/netpool","last_synced_at":"2026-01-27T00:25:27.555Z","repository":{"id":181772233,"uuid":"667283526","full_name":"yudhasubki/netpool","owner":"yudhasubki","description":"High-performance TCP connection pool for Go with a channel-driven, lock-free, and zero allocations.","archived":false,"fork":false,"pushed_at":"2025-12-15T02:15:24.000Z","size":61,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-16T03:28:50.788Z","etag":null,"topics":["go","golang","networking","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/yudhasubki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-17T06:52:56.000Z","updated_at":"2025-12-15T01:53:19.000Z","dependencies_parsed_at":"2023-07-17T07:55:10.123Z","dependency_job_id":null,"html_url":"https://github.com/yudhasubki/netpool","commit_stats":null,"previous_names":["yudhasubki/netpool"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/yudhasubki/netpool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Fnetpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Fnetpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Fnetpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Fnetpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yudhasubki","download_url":"https://codeload.github.com/yudhasubki/netpool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudhasubki%2Fnetpool/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28792959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T21:49:50.245Z","status":"ssl_error","status_checked_at":"2026-01-26T21:48:29.455Z","response_time":59,"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":["go","golang","networking","pool"],"created_at":"2026-01-27T00:25:26.782Z","updated_at":"2026-01-27T00:25:27.546Z","avatar_url":"https://github.com/yudhasubki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Netpool - Lock-Free Go TCP Connection Pool\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/yudhasubki/netpool.svg)](https://pkg.go.dev/github.com/yudhasubki/netpool)\n\n## 🚀 Performance\n\nNetpool is the Go connection pool. It uses a lock-free channel design with zero-allocation pass-by-value optimization.\n\n| Library | ns/op | Throughput | Memory | Allocations | Features |\n|---------|-------|-----------|--------|-------------|----------|\n| **netpool (Basic)** | **42 ns** | **23.8M ops/sec** | **0 B** | **0 allocs** | Maximum Speed (No Idle/Health) |\n| **netpool (Standard)**| **118 ns** | **8.4M ops/sec** | **0 B** | **0 allocs** | IdleTimeout, HealthCheck |\n| fatih/pool | 124 ns | 8.0M ops/sec | 64 B | 1 alloc | No HealthCheck |\n| silenceper/pool | 303 ns | 3.3M ops/sec | 48 B | 1 alloc | IdleTimeout, HealthCheck |\n\n## Features\n\n- **Lock-free** - Uses channels and atomics only\n- **Zero allocation** - No memory allocations on Get/Put\n- **Idle Timeout** - Automatically closes stale connections\n- **Health Check** - Validates connections before use\n- **Thread-safe** - Safe for concurrent use\n\n## Installation\n\n```bash\ngo get github.com/yudhasubki/netpool\n```\n\n## Quick Start\n\n### Standard Pool (Recommended)\nBest balance of features and performance (118 ns/op).\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"net\"\n    \"time\"\n    \n    \"github.com/yudhasubki/netpool\"\n)\n\nfunc main() {\n\t// Create a new pool\n\t// Factory function now accepts context for proper timeout/cancellation!\n\tpool, err := netpool.New(func(ctx context.Context) (net.Conn, error) {\n\t\tvar d net.Dialer\n\t\treturn d.DialContext(ctx, \"tcp\", \"127.0.0.1:8080\")\n\t}, netpool.Config{\n\t\tMaxPool:     100,\n\t\tMinPool:     10,\n\t\tMaxIdleTime: 30 * time.Second,\n\t\tDialTimeout: 5 * time.Second, \n\t})\n    \n    conn, _ := pool.Get()\n    defer pool.Put(conn)\n}\n```\n\n### Basic Pool (Maximum Performance)\nFor use cases needing absolute raw speed (~40 ns/op).\n**Note:** Does NOT support `MaxIdleTime` or `HealthCheck`.\n\n```go\n// Use NewBasic() instead of New()\npool, err := netpool.NewBasic(func() (net.Conn, error) {\n    return net.Dial(\"tcp\", \"localhost:6379\")\n}, netpool.Config{\n    MaxPool: 100,\n    MinPool: 10,\n})\n\nconn, _ := pool.Get()\ndefer pool.Put(conn)\n```\n\n## API\n\n### Creating a Pool\n\n```go\npool, err := netpool.New(factory, netpool.Config{\n    MaxPool:     100,              // Maximum connections\n    MinPool:     10,               // Minimum idle connections\n    DialTimeout: 5 * time.Second,  // Connection creation timeout\n    MaxIdleTime: 30 * time.Second, // Close connections idle too long\n    HealthCheck: pingFunc,         // Validate connection on Get()\n})\n```\n\n### Getting a Connection\n\n```go\n// Simple get (blocks if pool is full)\nconn, err := pool.Get()\n\n// Get with context (supports cancellation/timeout)\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nconn, err := pool.GetWithContext(ctx)\n```\n\n### Returning a Connection\n\n```go\n// Return healthy connection\npool.Put(conn)\n\n// Return with error (connection will be closed)\npool.PutWithError(conn, err)\n```\n\n### Pool Statistics\n\n```go\nstats := pool.Stats()\nfmt.Printf(\"Active: %d, Idle: %d, InUse: %d\\n\",\n    stats.Active, stats.Idle, stats.InUse)\n```\n\n## How It Works\n\nNetpool uses a **Pass-by-Value** channel design for maximum efficiency:\n\n1. **Wait-Free Path**: `Get()` and `Put()` operations use Go channels with value copying.\n2. **Zero Allocation**: Connection wrappers (`idleConn`) are passed by value (copying ~40 bytes), eliminating `sync.Pool` overhead and heap allocations.\n3. **Atomic State**: Pool size is tracked with `atomic.Int32` for contention-free reads.\n\nThis design beats standard `sync.Pool` or mutex-based implementations by reducing memory pressure and CPU cycles.\n\n## Running Benchmarks\n\n```bash\n# Run comparison with other libraries\ngo test -bench=BenchmarkComparison -benchmem ./...\n```\n\n## Credits\n\nThis project is inspired by the design and implementation of:\n\n- [fatih/pool](https://github.com/fatih/pool)\n- [silenceper/pool](https://github.com/silenceper/pool)\n\nWe thank the authors for their contributions to the Go ecosystem.\n\n## License\n\nMIT License - see [LICENSE](LICENSE) file.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudhasubki%2Fnetpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyudhasubki%2Fnetpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudhasubki%2Fnetpool/lists"}