{"id":16253475,"url":"https://github.com/alphadose/itogami","last_synced_at":"2025-03-16T13:30:41.792Z","repository":{"id":37743728,"uuid":"503022783","full_name":"alphadose/itogami","owner":"alphadose","description":"Fastest and most efficient goroutine pool (experimental)","archived":false,"fork":false,"pushed_at":"2022-10-16T16:09:11.000Z","size":39,"stargazers_count":137,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-27T09:30:41.077Z","etag":null,"topics":["concurrency","fastest","go","golang","goroutine","goroutine-pool","highly-concurrent","itogami","lock-free","low-latency","low-memory-footprint","pool","threadpool","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/alphadose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-13T15:57:15.000Z","updated_at":"2024-12-24T13:45:22.000Z","dependencies_parsed_at":"2022-07-12T16:44:31.910Z","dependency_job_id":null,"html_url":"https://github.com/alphadose/itogami","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fitogami","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fitogami/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fitogami/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphadose%2Fitogami/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphadose","download_url":"https://codeload.github.com/alphadose/itogami/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243815563,"owners_count":20352189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["concurrency","fastest","go","golang","goroutine","goroutine-pool","highly-concurrent","itogami","lock-free","low-latency","low-memory-footprint","pool","threadpool","worker-pool"],"created_at":"2024-10-10T15:17:31.501Z","updated_at":"2025-03-16T13:30:41.392Z","avatar_url":"https://github.com/alphadose.png","language":"Go","readme":"# Itogami\n\n\u003e An experimental goroutine pool implemented using a lock-free stack\n\nBy limiting concurrency with a fixed pool size and recycling goroutines using a stack, itogami saves a lot of memory as compared to using unlimited goroutines and remaining just as fast.\n\nBenchmarks to support the above claims [here](#benchmarks)\n\n**Note:- This work is experimental and should not be used in production**\n\n## Installation\n\nYou need Golang [1.19.x](https://go.dev/dl/) or above\n\n```bash\n$ go get github.com/alphadose/itogami\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\t\"sync/atomic\"\n\t\"time\"\n\n\t\"github.com/alphadose/itogami\"\n)\n\nconst runTimes uint32 = 1000\n\nvar sum uint32\n\nfunc myFunc(i uint32) {\n\tatomic.AddUint32(\u0026sum, i)\n\tfmt.Printf(\"run with %d\\n\", i)\n}\n\nfunc demoFunc() {\n\ttime.Sleep(10 * time.Millisecond)\n\tprintln(\"Hello World\")\n}\n\nfunc examplePool() {\n\tvar wg sync.WaitGroup\n\t// Use the common pool\n\tpool := itogami.NewPool(10)\n\n\tsyncCalculateSum := func() {\n\t\tdemoFunc()\n\t\twg.Done()\n\t}\n\tfor i := uint32(0); i \u003c runTimes; i++ {\n\t\twg.Add(1)\n\t\t// Submit task to the pool\n\t\tpool.Submit(syncCalculateSum)\n\t}\n\twg.Wait()\n\tprintln(\"finished all tasks\")\n}\n\nfunc examplePoolWithFunc() {\n\tvar wg sync.WaitGroup\n\t// Use the pool with a pre-defined function\n\tpool := itogami.NewPoolWithFunc(10, func(i uint32) {\n\t\tmyFunc(i)\n\t\twg.Done()\n\t})\n\tfor i := uint32(0); i \u003c runTimes; i++ {\n\t\twg.Add(1)\n\t\t// Invoke the function with a value\n\t\tpool.Invoke(i)\n\t}\n\twg.Wait()\n\tfmt.Printf(\"finish all tasks, result is %d\\n\", sum)\n}\n\nfunc main() {\n\texamplePool()\n\texamplePoolWithFunc()\n}\n```\n\n## Benchmarks\n\nBenchmarking was performed against:-\n\n1. Unlimited goroutines\n2. [Ants](https://github.com/panjf2000/ants)\n3. [Gamma-Zero-Worker-Pool](https://github.com/gammazero/workerpool)\n4. [golang.org/x/sync/errgroup](https://pkg.go.dev/golang.org/x/sync/errgroup)\n5. [Bytedance GoPool](https://github.com/bytedance/gopkg/tree/develop/util/gopool)\n\nPool size -\u003e 50k\n\nCPU -\u003e M1, arm64, 8 cores, 3.2 GHz\n\nOS -\u003e darwin\n\nResults were computed from [benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) of 30 cases\n```\nname                   time/op\nUnlimitedGoroutines-8   331ms ± 4%\nErrGroup-8              515ms ± 9%\nAntsPool-8              582ms ± 9%\nGammaZeroPool-8         740ms ±13%\nBytedanceGoPool-8       572ms ±18%\nItogamiPool-8           337ms ± 1%\n\nname                   alloc/op\nUnlimitedGoroutines-8  96.3MB ± 0%\nErrGroup-8              120MB ± 0%\nAntsPool-8             22.4MB ± 6%\nGammaZeroPool-8        18.8MB ± 1%\nBytedanceGoPool-8      82.2MB ± 2%\nItogamiPool-8          25.6MB ± 2%\n\nname                   allocs/op\nUnlimitedGoroutines-8   2.00M ± 0%\nErrGroup-8              3.00M ± 0%\nAntsPool-8              1.10M ± 2%\nGammaZeroPool-8         1.08M ± 0%\nBytedanceGoPool-8       2.59M ± 1%\nItogamiPool-8           1.08M ± 0%\n```\n\nThe following conclusions can be drawn from the above results:-\n\n1. [Itogami](https://github.com/alphadose/itogami) is the fastest among all goroutine pool implementations and slightly slower than unlimited goroutines\n2. [Itogami](https://github.com/alphadose/itogami) has the least `allocs/op` and hence the memory usage scales really well with high load\n3. The memory used per operation is in the acceptable range of other pools and drastically lower than unlimited goroutines\n4. The tolerance (± %) for [Itogami](https://github.com/alphadose/itogami) is quite low for all 3 metrics indicating that the algorithm is quite stable overall\n\nBenchmarking code available [here](https://github.com/alphadose/go-threadpool-benchmarks)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphadose%2Fitogami","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphadose%2Fitogami","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphadose%2Fitogami/lists"}