Maglev
A Google Maglev Hashing Algorithm implement in Golang
Install / Use
/learn @kkdai/MaglevREADME
Maglev: A Google Maglev Hashing Algorithm implement in Golang

What is Maglev
Maglev is Google’s network load balancer. It is a large distributed software system that runs on commodity Linux servers. Unlike traditional hardware network load balancers, it does not require a specialized physical rack deployment, and its capacity can be easily adjusted by adding or removing servers. (cite from paper)
Here is a Chinese reading note about Maglev: [論文中文導讀] Maglev : A Fast and Reliable Software Network Load Balancer (using Consistent Hashing)
Installation and Usage
Install
go get github.com/kkdai/maglev
Usage
func main() {
sizeN := 5
lookupSizeM := 13 //(must be prime number)
var names []string
for i := 0; i < sizeN; i++ {
names = append(names, fmt.Sprintf("backend-%d", i))
}
//backend-0 ~ backend-4
mm, err := NewMaglev(names, lookupSizeM)
if err != nil {
log.Fatal("NewMaglev failed:", err)
}
v, err := mm.Get("IP1")
fmt.Println("node1:", v)
//node1: backend-2
v, _ = mm.Get("IP2")
log.Println("node2:", v)
//node2: backend-1
v, _ = mm.Get("IPasdasdwni2")
log.Println("node3:", v)
//node3: backend-0
if err := mm.Remove("backend-0"); err != nil {
log.Fatal("Remove failed", err)
}
v, _ = mm.Get("IPasdasdwni2")
log.Println("node3-D:", v)
//node3-D: Change from "backend-0" to "backend-1"
}
Inspired By
- Wiki Consistent_hashing
- Go implementation of maglev hashing
- 每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)
- Distributed Systems Part-1: A peek into consistent hashing!
Project52
It is one of my project 52.
License
This is under the Apache 2.0 license. See the LICENSE file for details.
Related Skills
node-connect
339.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
339.5kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
