Skip to content

Instantly share code, notes, and snippets.

@cezarsa
Created October 26, 2020 19:09
Show Gist options
  • Save cezarsa/09237d9500865441bbbd166d78f6973b to your computer and use it in GitHub Desktop.
Save cezarsa/09237d9500865441bbbd166d78f6973b to your computer and use it in GitHub Desktop.
func BenchmarkClusterIP(b *testing.B) {
nSvcs := 1000
endpointsPerSvc := 2
var allSvcs []*v1.Service
var allEndpoints []*v1.Endpoints
for i := 0; i < nSvcs; i++ {
allSvcs = append(allSvcs, makeTestService("ns1", fmt.Sprintf("svc-%d", i), func(svc *v1.Service) {
ip := net.ParseIP("10.0.0.0").To4()
ip[2] = byte(uint32(i+1) >> 8 & 0xff)
ip[3] = byte(uint32(i+1) & 0xff)
svc.Spec.ClusterIP = ip.String()
svc.Spec.Ports = []v1.ServicePort{{
Name: "p80",
Port: int32(80),
Protocol: v1.ProtocolTCP,
}}
}))
for j := 0; j < endpointsPerSvc; j++ {
allEndpoints = append(allEndpoints, makeTestEndpoints("ns1", fmt.Sprintf("svc-%d", i), func(ept *v1.Endpoints) {
ept.Subsets = []v1.EndpointSubset{{
Addresses: []v1.EndpointAddress{{
IP: "10.180.0.1",
}},
Ports: []v1.EndpointPort{{
Name: "p80",
Port: int32(80),
Protocol: v1.ProtocolTCP,
}},
}}
}))
}
}
ipt := iptablestest.NewFake()
ipset := ipsettest.NewFake(testIPSetVersion)
execer := exec.New()
ipvs := utilipvs.New(execer)
err := execer.Command("ipvsadm", "-C").Run()
if err != nil {
b.Fatal(err)
}
fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, false)
makeServiceMap(fp, allSvcs...)
makeEndpointsMap(fp, allEndpoints...)
// First run will insert ipvs services and destinations
fp.syncProxyRules()
// Reset and run the benchmark proper
b.ResetTimer()
for i := 0; i < b.N; i++ {
fp.syncProxyRules()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment