Skip to content

High-performance, lock-free MPMC ring buffer and thread-safe round-robin balancer for Go 1.23+

License

Notifications You must be signed in to change notification settings

imatakatsu/ringer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ringer

ringer is a lightweight Go library providing lock-free data structures. It features an MPMC (Multi-Producer Multi-Consumer) RingBuffer and a thread-safe Rotator.

features

  • Zero Locks: Built on atomic operations for maximum throughput.
  • Cache-Optimized: Prevents false sharing with CPU cache line padding.
  • Modern API: Rotator provide iterator with iter.Seq (Go 1.23+)

Installation

go get github.com/imatakatsu/ringer

Usage

1. RingBuffer (MPMC Queue)

package main

import (
	"fmt"
	"github.com/imatakatsu/ringer"
)

func main() {
	// Create a buffer from an existing slice
	buf := ringer.BufferFromSlice([]string{"Alexey", "Georgy"})

	// Pop an item
	val, _ := buf.Pop()
	fmt.Println("First user:", *val)

	// Push it back
	_ = buf.Push(val)
}

output

First user: Alexey

2. Rotator (Round-Robin)

package main

import (
	"fmt"
	"github.com/imatakatsu/ringer"
)

func main() {
	r := ringer.NewRotator([]string{"node-1", "node-2", "node-3"})

	// Infinite rotation using Ring() iterator (Go 1.23+)
	count := 0
	for node := range r.Ring() {
		fmt.Println(node)
		count++
		if count == 4 { break }
	}
}

output

node-1
node-2
node-3
node-1

godoc comments generated by Gemini 3 Flash, they may contain any mistakes

About

High-performance, lock-free MPMC ring buffer and thread-safe round-robin balancer for Go 1.23+

Topics

Resources

License

Stars

Watchers

Forks

Languages