{"id":17537744,"url":"https://github.com/lthibault/turbine","last_synced_at":"2025-04-23T21:08:28.650Z","repository":{"id":87128277,"uuid":"177494597","full_name":"lthibault/turbine","owner":"lthibault","description":"High-performance alternative to channels with pipelining","archived":false,"fork":false,"pushed_at":"2019-03-26T12:34:25.000Z","size":13,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T21:08:22.267Z","etag":null,"topics":["channel","concurrency-patterns","disruptor","goroutine","goroutine-safe","message-passing","pipeline","thread"],"latest_commit_sha":null,"homepage":null,"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/lthibault.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-25T01:43:03.000Z","updated_at":"2022-03-19T01:09:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"4beef801-de11-4672-9611-c4d5f6ce64d1","html_url":"https://github.com/lthibault/turbine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lthibault%2Fturbine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lthibault%2Fturbine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lthibault%2Fturbine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lthibault%2Fturbine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lthibault","download_url":"https://codeload.github.com/lthibault/turbine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514786,"owners_count":21443209,"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":["channel","concurrency-patterns","disruptor","goroutine","goroutine-safe","message-passing","pipeline","thread"],"created_at":"2024-10-20T20:42:39.504Z","updated_at":"2025-04-23T21:08:28.602Z","avatar_url":"https://github.com/lthibault.png","language":"Go","readme":"# turbine\n\n[![Godoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/lthibault/turbine/pkg) [![Go Report Card](https://goreportcard.com/badge/github.com/lthibault/turbine?style=flat-square)](https://goreportcard.com/report/github.com/lthibault/turbine)\n\nLock-free pipeline for inter-thread message passing.\n\n## Overview\n\nTurbine is a concurrency data structure that allows for lock-free message passing between threads.\n\nIt's a special kind of ring-buffer that supports batched reading and writng, as well as multi-stage, concurrent pipelines.  It is allocation and garbage free, and exhibits latency on the order of nanoseconds.\n\nTurbine is based heavily on [go-disruptor](https://github.com/smartystreets/go-disruptor). It features a simplified architecture, and fixes the data-races inherent in go-disruptor's\ndesign.\n\n## Why Turbine\n\nTurbine is not suitable for all scenarios.  **When in doubt, use channels.**  With Turbine, you lose many of Go's most useful concurrency features:\n\n1. `select` statements\n2. synchronous message passing (i.e.: async only)\n3. synchronous close semantics\n\nThere are two situations in which Turbine is useful.\n\nThe first is when the concurrency problem can be modeled as a concurrent pipeline with independent stages that run in strict order.  This kind of problem is (in our opinion) more naturally expressed with `Turbine` than with channels, though your mileage may vary.\n\nThe second use case is in ultra low-latency environments where jitter must be kept to a minimum.\n\n## Benchmarks\n\nBenchmarks can be run as follows:\n\n```bash\n$ go test -bench=. ./...\n\ngoos: darwin\ngoarch: amd64\npkg: github.com/lthibault/turbine/pkg\nBenchmarkTurbine/ReserveOne-4           50000000                37.2 ns/op             0 B/op          0 allocs/op\nBenchmarkTurbine/ReserveMany-4          300000000                6.33 ns/op            0 B/op          0 allocs/op\nBenchmarkChan/Unbuffered-4               5000000               361 ns/op               0 B/op          0 allocs/op\nBenchmarkChan/Buffered-1-4               5000000               261 ns/op               0 B/op          0 allocs/op\nBenchmarkChan/Buffered-16-4             10000000               113 ns/op               0 B/op          0 allocs/op\nPASS\nok      github.com/lthibault/turbine/pkg        9.448s\n```\n\nSuggestions for improving benchmark accuracy are welcome.\n\n## Quickstart\n\nThe following demonstrates the use of `turbine`.  Note the absence of `interface{}`!\n\n```go\npackage main\n\nimport (\n    \"log\"\n\n    turbine \"github.com/lthibault/turbine/pkg\"\n)\n\nconst (\n    cap  = 1024 // must be a power of 2\n    mask = cap - 1\n)\n\nvar ring = [cap]packet{}\n\ntype packet struct {\n    Value int\n}\n\ntype multiplier struct{}\n\nfunc (multiplier) Consume(lower, upper int64) {\n    for seq := lower; seq \u003c= upper; seq++ {\n        ring[seq\u0026mask].Value *= 10\n    }\n}\n\ntype logger struct{}\n\nfunc (logger) Consume(lower, upper int64) {\n    var msg packet\n    for seq := lower; seq \u003c= upper; seq++ {\n        msg = ring[seq\u0026mask]\n        log.Println(msg.Value)\n    }\n}\n\nfunc main() {\n    t := turbine.New(cap, multiplier{}, logger{})\n    t.Start()\n    defer t.Stop()\n        w := t.Writer()\n\n    for i := 0; i \u003c 100; i++ {\n        seq := w.Reserve(1)\n        ring[seq\u0026mask].Value = i\n        w.Commit(seq)\n    }\n}\n\n```\n\n## Projects using Turbine\n\n1. [CASM](https://github.com/lthibault/casm)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flthibault%2Fturbine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flthibault%2Fturbine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flthibault%2Fturbine/lists"}