Skip to content

Commit

Permalink
nsqlookupd: benchmark topic lookup and channel lookup separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ploxiln committed Jun 2, 2018
1 parent 0bf9b67 commit 09e0aaa
Showing 1 changed file with 58 additions and 21 deletions.
79 changes: 58 additions & 21 deletions nsqlookupd/registration_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,21 @@ func TestRegistrationDB(t *testing.T) {
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)
regT := Registration{"topic", "t" + strconv.Itoa(i), ""}
regCa := Registration{"channel", "t" + strconv.Itoa(i), "ca" + strconv.Itoa(i)}
regCb := Registration{"channel", "t" + strconv.Itoa(i), "cb" + strconv.Itoa(i)}
regDB.AddRegistration(regT)
regDB.AddRegistration(regCa)
regDB.AddRegistration(regCb)
for j := 0; j < producers; j++ {
p := Producer{
peerInfo: &PeerInfo{
id: "p" + strconv.Itoa(j),
},
}
regDB.AddProducer(reg, &p)
regDB.AddProducer(regT, &p)
regDB.AddProducer(regCa, &p)
regDB.AddProducer(regCb, &p)
}
}
return regDB
Expand All @@ -135,13 +137,24 @@ func benchmarkLookupRegistrations(b *testing.B, registrations int, producers int
resRegs = res
}

func benchmarkFindProducers(b *testing.B, registrations int, producers int) {
func benchmarkFindTopicProducers(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)
res = regDB.FindProducers("topic", "t"+j, "")
}
resPros = res
}

func benchmarkFindChannelProducers(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, "cb"+j)
}
resPros = res
}
Expand Down Expand Up @@ -170,26 +183,50 @@ func BenchmarkLookupRegistrations512x2048(b *testing.B) {
benchmarkLookupRegistrations(b, 512, 2048)
}

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

func BenchmarkFindTopicProducers8x64(b *testing.B) {
benchmarkFindTopicProducers(b, 8, 64)
}

func BenchmarkFindTopicProducers64x64(b *testing.B) {
benchmarkFindTopicProducers(b, 64, 64)
}

func BenchmarkFindTopicProducers64x512(b *testing.B) {
benchmarkFindTopicProducers(b, 64, 512)
}

func BenchmarkFindTopicProducers512x512(b *testing.B) {
benchmarkFindTopicProducers(b, 512, 512)
}

func BenchmarkFindTopicProducers512x2048(b *testing.B) {
benchmarkFindTopicProducers(b, 512, 2048)
}

func BenchmarkFindChannelProducers8x8(b *testing.B) {
benchmarkFindChannelProducers(b, 8, 8)
}

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

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

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

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

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

0 comments on commit 09e0aaa

Please sign in to comment.