Skip to content

Commit

Permalink
nsqlookupd: RegistrationDB benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
andyxning authored and ploxiln committed Jun 2, 2018
1 parent ce569be commit 0bf9b67
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions nsqlookupd/registration_db_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nsqlookupd

import (
"math/rand"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -96,3 +98,98 @@ func TestRegistrationDB(t *testing.T) {
k = db.FindRegistrations("c", "*", "*").Keys()
test.Equal(t, 0, len(k))
}

func fillRegDB(registrations int, producers int) *RegistrationDB {
regDB := NewRegistrationDB()
for i := 0; i < registrations; i++ {
reg := Registration{
Category: "channel",
Key: "t" + strconv.Itoa(i),
SubKey: "c" + strconv.Itoa(i),
}
regDB.AddRegistration(reg)
for j := 0; j < producers; j++ {
p := Producer{
peerInfo: &PeerInfo{
id: "p" + strconv.Itoa(j),
},
}
regDB.AddProducer(reg, &p)
}
}
return regDB
}

// to avoid optimizations bypassing benchmarks
var resRegs Registrations
var resPros Producers

func benchmarkLookupRegistrations(b *testing.B, registrations int, producers int) {
var res Registrations
regDB := fillRegDB(registrations, producers)
b.ResetTimer()
for i := 0; i < b.N; i++ {
j := strconv.Itoa(rand.Intn(producers))
res = regDB.LookupRegistrations("p" + j)
}
resRegs = res
}

func benchmarkFindProducers(b *testing.B, registrations int, producers int) {
var res Producers
regDB := fillRegDB(registrations, producers)
b.ResetTimer()
for i := 0; i < b.N; i++ {
j := strconv.Itoa(rand.Intn(registrations))
res = regDB.FindProducers("channel", "t"+j, "c"+j)
}
resPros = res
}

func BenchmarkLookupRegistrations8x8(b *testing.B) {
benchmarkLookupRegistrations(b, 8, 8)
}

func BenchmarkLookupRegistrations8x64(b *testing.B) {
benchmarkLookupRegistrations(b, 8, 64)
}

func BenchmarkLookupRegistrations64x64(b *testing.B) {
benchmarkLookupRegistrations(b, 64, 64)
}

func BenchmarkLookupRegistrations64x512(b *testing.B) {
benchmarkLookupRegistrations(b, 64, 512)
}

func BenchmarkLookupRegistrations512x512(b *testing.B) {
benchmarkLookupRegistrations(b, 512, 512)
}

func BenchmarkLookupRegistrations512x2048(b *testing.B) {
benchmarkLookupRegistrations(b, 512, 2048)
}

func BenchmarkFindProducers8x8(b *testing.B) {
benchmarkFindProducers(b, 8, 8)
}

func BenchmarkFindProducers8x64(b *testing.B) {
benchmarkFindProducers(b, 8, 64)
}

func BenchmarkFindProducers64x64(b *testing.B) {
benchmarkFindProducers(b, 64, 64)
}

func BenchmarkFindProducers64x512(b *testing.B) {
benchmarkFindProducers(b, 64, 512)
}

func BenchmarkFindProducers512x512(b *testing.B) {
benchmarkFindProducers(b, 512, 512)
}

func BenchmarkFindProducers512x2048(b *testing.B) {
benchmarkFindProducers(b, 512, 2048)
}

0 comments on commit 0bf9b67

Please sign in to comment.