Skip to content

Commit

Permalink
separate benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Nov 26, 2024
1 parent e582d43 commit 3fef6e8
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 110 deletions.
66 changes: 66 additions & 0 deletions pkg/roles/dns/handler_etcd_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package dns_test

import (
"testing"

"beryju.io/gravity/pkg/instance"
"beryju.io/gravity/pkg/roles/dns"
"beryju.io/gravity/pkg/roles/dns/types"
"beryju.io/gravity/pkg/tests"
d "github.com/miekg/dns"
)

func BenchmarkRoleDNS_Etcd(b *testing.B) {
defer tests.Setup(nil)()
rootInst := instance.New()
ctx := tests.Context()
inst := rootInst.ForRole("dns", ctx)
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
TestZone,
).String(),
tests.MustJSON(dns.Zone{
HandlerConfigs: []map[string]interface{}{
{
"type": "etcd",
},
},
}),
))
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
TestZone,
"foo",
types.DNSRecordTypeA,
"0",
).String(),
tests.MustJSON(dns.Record{
Data: "10.1.2.3",
}),
))

role := dns.New(inst)
_ = role.Start(ctx, RoleConfig())
defer role.Stop()

b.ResetTimer()
for i := 0; i < b.N; i++ {
fw := NewNullDNSWriter()
role.Handler(fw, &d.Msg{
Question: []d.Question{
{
Name: "foo.example.com.",
Qtype: d.TypeA,
Qclass: d.ClassINET,
},
},
})
_ = fw.Msg()
}
}
55 changes: 0 additions & 55 deletions pkg/roles/dns/handler_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,61 +69,6 @@ func TestRoleDNS_Etcd(t *testing.T) {
assert.Equal(t, net.ParseIP("10.1.2.3").String(), ans.(*d.A).A.String())
}

func BenchmarkRoleDNS_Etcd(b *testing.B) {
defer tests.Setup(nil)()
rootInst := instance.New()
ctx := tests.Context()
inst := rootInst.ForRole("dns", ctx)
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
TestZone,
).String(),
tests.MustJSON(dns.Zone{
HandlerConfigs: []map[string]interface{}{
{
"type": "etcd",
},
},
}),
))
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
TestZone,
"foo",
types.DNSRecordTypeA,
"0",
).String(),
tests.MustJSON(dns.Record{
Data: "10.1.2.3",
}),
))

role := dns.New(inst)
_ = role.Start(ctx, RoleConfig())
defer role.Stop()

b.ResetTimer()
for i := 0; i < b.N; i++ {
fw := NewNullDNSWriter()
role.Handler(fw, &d.Msg{
Question: []d.Question{
{
Name: "foo.example.com.",
Qtype: d.TypeA,
Qclass: d.ClassINET,
},
},
})
_ = fw.Msg()
}
}

// Test DNS Entry at root of zone
func TestRoleDNS_Etcd_Root(t *testing.T) {
defer tests.Setup(t)()
Expand Down
66 changes: 66 additions & 0 deletions pkg/roles/dns/handler_memory_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package dns_test

import (
"testing"

"beryju.io/gravity/pkg/instance"
"beryju.io/gravity/pkg/roles/dns"
"beryju.io/gravity/pkg/roles/dns/types"
"beryju.io/gravity/pkg/tests"
d "github.com/miekg/dns"
)

func BenchmarkRoleDNS_Memory(b *testing.B) {
defer tests.Setup(nil)()
rootInst := instance.New()
ctx := tests.Context()
inst := rootInst.ForRole("dns", ctx)
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
".",
).String(),
tests.MustJSON(dns.Zone{
HandlerConfigs: []map[string]interface{}{
{
"type": "memory",
},
},
}),
))
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
".",
"foo",
types.DNSRecordTypeA,
"0",
).String(),
tests.MustJSON(dns.Record{
Data: "10.1.2.3",
}),
))

role := dns.New(inst)
_ = role.Start(ctx, RoleConfig())
defer role.Stop()

b.ResetTimer()
for i := 0; i < b.N; i++ {
fw := NewNullDNSWriter()
role.Handler(fw, &d.Msg{
Question: []d.Question{
{
Name: "foo.",
Qtype: d.TypeA,
Qclass: d.ClassINET,
},
},
})
_ = fw.Msg()
}
}
55 changes: 0 additions & 55 deletions pkg/roles/dns/handler_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,61 +66,6 @@ func TestRoleDNS_Memory(t *testing.T) {
assert.Equal(t, net.ParseIP("10.1.2.3").String(), ans.(*d.A).A.String())
}

func BenchmarkRoleDNS_Memory(b *testing.B) {
defer tests.Setup(nil)()
rootInst := instance.New()
ctx := tests.Context()
inst := rootInst.ForRole("dns", ctx)
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
".",
).String(),
tests.MustJSON(dns.Zone{
HandlerConfigs: []map[string]interface{}{
{
"type": "memory",
},
},
}),
))
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
".",
"foo",
types.DNSRecordTypeA,
"0",
).String(),
tests.MustJSON(dns.Record{
Data: "10.1.2.3",
}),
))

role := dns.New(inst)
_ = role.Start(ctx, RoleConfig())
defer role.Stop()

b.ResetTimer()
for i := 0; i < b.N; i++ {
fw := NewNullDNSWriter()
role.Handler(fw, &d.Msg{
Question: []d.Question{
{
Name: "foo.",
Qtype: d.TypeA,
Qclass: d.ClassINET,
},
},
})
_ = fw.Msg()
}
}

func TestRoleDNS_Memory_Wildcard(t *testing.T) {
defer tests.Setup(t)()
rootInst := instance.New()
Expand Down
60 changes: 60 additions & 0 deletions pkg/roles/dns/role_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dns_test

import (
"testing"

"beryju.io/gravity/pkg/instance"
"beryju.io/gravity/pkg/roles/dns"
"beryju.io/gravity/pkg/roles/dns/types"
"beryju.io/gravity/pkg/tests"
d "github.com/miekg/dns"
)

func BenchmarkRoleDNS_DefaultRootZone(b *testing.B) {
defer tests.Setup(nil)()
rootInst := instance.New()
ctx := tests.Context()
inst := rootInst.ForRole("dns", ctx)
tests.PanicIfError(inst.KV().Put(
ctx,
inst.KV().Key(
types.KeyRole,
types.KeyZones,
".",
).String(),
tests.MustJSON(dns.Zone{
HandlerConfigs: []map[string]interface{}{
{
"type": "memory",
},
{
"type": "etcd",
},
{
"type": "forward_ip",
"to": []string{"127.0.0.1:1053"},
"cache_ttl": 3600,
},
},
}),
))

role := dns.New(inst)
_ = role.Start(ctx, RoleConfig())
defer role.Stop()

b.ResetTimer()
for i := 0; i < b.N; i++ {
fw := NewNullDNSWriter()
role.Handler(fw, &d.Msg{
Question: []d.Question{
{
Name: "gravity.beryju.io.",
Qtype: d.TypeA,
Qclass: d.ClassINET,
},
},
})
_ = fw.Msg()
}
}

0 comments on commit 3fef6e8

Please sign in to comment.