Skip to content

Instantly share code, notes, and snippets.

@wutlu
Last active December 18, 2025 19:17
Show Gist options
  • Select an option

  • Save wutlu/deeb02f4266dd4008135771b8d6d90f9 to your computer and use it in GitHub Desktop.

Select an option

Save wutlu/deeb02f4266dd4008135771b8d6d90f9 to your computer and use it in GitHub Desktop.
BoltCache Pipelined Benchmark
package main
import (
"bufio"
"fmt"
"net"
"sync"
"time"
)
const (
pipelineSize = 100
numOps = 1000000
)
func benchmarkPipelined(host string, port int, name string) (setOps, getOps float64) {
addr := fmt.Sprintf("%s:%d", host, port)
// SET benchmark
start := time.Now()
conn, err := net.Dial("tcp", addr)
if err != nil {
fmt.Printf("Failed to connect to %s: %v\n", name, err)
return 0, 0
}
defer conn.Close()
reader := bufio.NewReader(conn)
// Send pipelined SETs
for i := 0; i < numOps/pipelineSize; i++ {
batch := ""
for j := 0; j < pipelineSize; j++ {
batch += fmt.Sprintf("SET key%d value%d\n", i*pipelineSize+j, i*pipelineSize+j)
}
conn.Write([]byte(batch))
// Read responses
for j := 0; j < pipelineSize; j++ {
reader.ReadString('\n')
}
}
setDuration := time.Since(start).Seconds()
setOps = float64(numOps) / setDuration
// GET benchmark
start = time.Now()
for i := 0; i < numOps/pipelineSize; i++ {
batch := ""
for j := 0; j < pipelineSize; j++ {
batch += fmt.Sprintf("GET key%d\n", i*pipelineSize+j)
}
conn.Write([]byte(batch))
// Read responses
for j := 0; j < pipelineSize; j++ {
reader.ReadString('\n')
}
}
getDuration := time.Since(start).Seconds()
getOps = float64(numOps) / getDuration
return setOps, getOps
}
func main() {
fmt.Println("╔═══════════════════════════════════════════════════════════════════╗")
fmt.Println("║ BoltCache vs Redis - Pipelined Benchmark (P=100) ║")
fmt.Println("╠═══════════════════════════════════════════════════════════════════╣")
var wg sync.WaitGroup
var boltSet, boltGet, redisSet, redisGet float64
wg.Add(2)
// BoltCache benchmark (gnet server on 6381)
go func() {
defer wg.Done()
boltSet, boltGet = benchmarkPipelined("localhost", 6381, "BoltCache")
}()
// Redis benchmark
go func() {
defer wg.Done()
redisSet, redisGet = benchmarkPipelined("localhost", 6379, "Redis")
}()
wg.Wait()
fmt.Println("║ SET ops/sec GET ops/sec ║")
fmt.Printf("║ BoltCache Ultra: %10.0f %10.0f ║\n", boltSet, boltGet)
fmt.Printf("║ Redis: %10.0f %10.0f ║\n", redisSet, redisGet)
fmt.Println("╠═══════════════════════════════════════════════════════════════════╣")
setRatio := boltSet / redisSet
getRatio := boltGet / redisGet
if setRatio > 1.0 {
fmt.Printf("║ SET: BoltCache is %.1fx FASTER than Redis ║\n", setRatio)
} else {
fmt.Printf("║ SET: Redis is %.1fx FASTER than BoltCache ║\n", 1.0/setRatio)
}
if getRatio > 1.0 {
fmt.Printf("║ GET: BoltCache is %.1fx FASTER than Redis ║\n", getRatio)
} else {
fmt.Printf("║ GET: Redis is %.1fx FASTER than BoltCache ║\n", 1.0/getRatio)
}
fmt.Println("╚═══════════════════════════════════════════════════════════════════╝")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment