mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
plugin/forward: fast-path string comparison in isAllowedDomain (#8385)
* test: add benchmark cases for Request IP/Port and parseRequest Signed-off-by: Manuel Rüger <manuel@rueg.eu> * test(kubernetes): add BenchmarkServices and BenchmarkServicesHeadless Signed-off-by: Manuel Rüger <manuel@rueg.eu> * perf(forward): fast-path string comparison in isAllowedDomain Signed-off-by: Manuel Rüger <manuel@rueg.eu> --------- Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
@@ -493,3 +493,33 @@ func TestServicesAuthority(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkServices(b *testing.B) {
|
||||||
|
k := New([]string{"inter.webs.tests."})
|
||||||
|
k.APIConn = APIConnServiceTest{}
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetQuestion("svc1.testns.svc.inter.webs.tests.", dns.TypeA)
|
||||||
|
state := request.Request{Zone: k.Zones[0], Req: m}
|
||||||
|
|
||||||
|
b.ReportAllocs()
|
||||||
|
for b.Loop() {
|
||||||
|
_, _ = k.Services(ctx, state, false, plugin.Options{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkServicesHeadless(b *testing.B) {
|
||||||
|
k := New([]string{"inter.webs.tests."})
|
||||||
|
k.APIConn = APIConnServiceTest{}
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetQuestion("hdls1.testns.svc.inter.webs.tests.", dns.TypeA)
|
||||||
|
state := request.Request{Zone: k.Zones[0], Req: m}
|
||||||
|
|
||||||
|
b.ReportAllocs()
|
||||||
|
for b.Loop() {
|
||||||
|
_, _ = k.Services(ctx, state, false, plugin.Options{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,3 +63,10 @@ func TestParseInvalidRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const zone = "inter.webs.tests."
|
const zone = "inter.webs.tests."
|
||||||
|
|
||||||
|
func BenchmarkParseRequest(b *testing.B) {
|
||||||
|
b.ReportAllocs()
|
||||||
|
for b.Loop() {
|
||||||
|
_, _ = parseRequest("1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", zone, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -381,3 +381,23 @@ func TestRequestClear(t *testing.T) {
|
|||||||
t.Errorf("Expected st.port to be cleared after Clear")
|
t.Errorf("Expected st.port to be cleared after Clear")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkRequestIP(b *testing.B) {
|
||||||
|
st := testRequest()
|
||||||
|
b.ReportAllocs()
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
st.Clear()
|
||||||
|
_ = st.IP()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkRequestPort(b *testing.B) {
|
||||||
|
st := testRequest()
|
||||||
|
b.ReportAllocs()
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
st.Clear()
|
||||||
|
_ = st.Port()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user