{"id":29480973,"url":"https://github.com/dk-open/ring","last_synced_at":"2025-07-14T23:55:14.129Z","repository":{"id":304654211,"uuid":"1019388103","full_name":"dk-open/ring","owner":"dk-open","description":"High-performance lock-free SPMC ring buffer with two-phase dequeue protocol","archived":false,"fork":false,"pushed_at":"2025-07-14T13:12:12.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-14T14:58:10.720Z","etag":null,"topics":["golang","hft","high-performance","lock-free","producer-consumer","ring-buffer","spmc","zero-allocation"],"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/dk-open.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,"zenodo":null}},"created_at":"2025-07-14T08:51:30.000Z","updated_at":"2025-07-14T13:12:15.000Z","dependencies_parsed_at":"2025-07-14T14:58:13.872Z","dependency_job_id":"b563d253-bed6-419a-8921-2ceca0ba5a80","html_url":"https://github.com/dk-open/ring","commit_stats":null,"previous_names":["dk-open/ring"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/dk-open/ring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk-open%2Fring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk-open%2Fring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk-open%2Fring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk-open%2Fring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dk-open","download_url":"https://codeload.github.com/dk-open/ring/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk-open%2Fring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265375347,"owners_count":23755216,"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":["golang","hft","high-performance","lock-free","producer-consumer","ring-buffer","spmc","zero-allocation"],"created_at":"2025-07-14T23:55:13.667Z","updated_at":"2025-07-14T23:55:14.094Z","avatar_url":"https://github.com/dk-open.png","language":"Go","readme":"# ring\nHigh-performance lock-free SPMC ring buffer with two-phase dequeue protocol and callback-based safety\n\n![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dk-open/ring)](https://goreportcard.com/report/github.com/dk-open/ring)\n[![codecov](https://codecov.io/gh/dk-open/ring/graph/badge.svg?token=FGK3F49GS4)](https://codecov.io/gh/dk-open/ring)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/dk-open/ring)](https://github.com/dk-open/ring)\n[![GitHub release](https://img.shields.io/github/release/dk-open/ring.svg)](https://github.com/dk-open/ring/releases)\n[![GitHub issues](https://img.shields.io/github/issues/dk-open/ring)](https://github.com/dk-open/ring/issues)\n\n## Overview\n\n`ringqueue` is a blazing-fast, lock-free ring buffer (queue) implementation for Go, inspired by Disruptor and optimized for low-latency, high-throughput scenarios. Designed for HFT, real-time systems, and any case where garbage-free, wait-free operations are required.\n\n- No dependencies\n- Generic (Go 1.18+)\n- CAS-based head/tail, false sharing padding\n- ABA protection\n- Busy-spin and adaptive exponential backoff\n- Supports multiple consumers (SPMC/MPMC)\n\n\n## Features\n- High-performance, lock-free queue with atomic operations\n- Efficient memory usage (single buffer allocation)\n- Dual-Counter System\n- Two-phase dequeue protocol for safe concurrent access\n- ABA protection\n- Wait-free progress\n- Configurable for concurrent readers\n- Busy-spin + adaptive backoff to minimize latency spikes\n- Padding to avoid false sharing on modern CPUs\n\n##  When to Use\n- High-frequency trading engines\n- Real-time data pipelines\n- Metrics/event aggregation\n- Anywhere you want the speed of a ring buffer without GC churn or locks\n\n## Example Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/dk-open/ring\"\n)\n\nfunc main() {\n\tctx := context.Background()\n    r := ring.New[int](10) // Create a new ring buffer with a capacity of 10\n\n\tgo func() {\n\t\t// Enqueue some items\n\t\tfor i := 0; i \u003c 10; i++ {\n\t\t\tif err := r.Enqueue(ctx, i); err != nil {\n\t\t\t\tfmt.Printf(\"Error enqueuing item %d: %v\\n\", i, err)\n\t\t\t} else {\n\t\t\t\tfmt.Printf(\"Enqueued item %d\\n\", i)\n\t\t\t}\n\t\t}\n\t}()\n\n    // Dequeue items\n    for i := 0; i \u003c 10; i++ {\n        item, err := r.Dequeue(ctx)\n        if err != nil {\n            fmt.Printf(\"Error dequeuing item: %v\\n\", err)\n            continue\n        }\n        fmt.Printf(\"Dequeued item: %d\\n\", item)\n    }\n}\n\n```\n\n\n## Benchmarks\n\n```bash\nBenchmarkQueue_CompareGoImplementations\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_1\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_1-10         \t34370985\t        40.08 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_2\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_2-10         \t27501936\t        43.82 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_4\nBenchmarkQueue/RingQueue_Capacity:_256_Reader:_4-10         \t20567461\t        61.90 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_1\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_1-10        \t20232192\t        61.67 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_2\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_2-10        \t13916404\t        80.26 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_4\nBenchmarkQueue/GoChannels_Capacity:_256_Reader:_4-10        \t 4143522\t       293.7 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_1\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_1-10        \t33240498\t        41.36 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_2\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_2-10        \t28821038\t        41.58 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_4\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_4-10        \t24417829\t        46.22 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_8\nBenchmarkQueue/RingQueue_Capacity:_1024_Reader:_8-10        \t20314622\t        61.51 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_1\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_1-10       \t32176396\t        37.01 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_2\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_2-10       \t26126785\t        45.66 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_4\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_4-10       \t 9999576\t       118.0 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_8\nBenchmarkQueue/GoChannels_Capacity:_1024_Reader:_8-10       \t 5259519\t       242.9 ns/op\t       0 B/op\t       0 allocs/op\n\n\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk-open%2Fring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdk-open%2Fring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk-open%2Fring/lists"}