Skip to content

Commit 2e15065

Browse files
Add benchmark for naive endpoint Get so we can measure it
Baseline: ``` BenchmarkGet-12 100000 119635 ns/op 20110 B/op 206 allocs/op BenchmarkWatchHTTP-12 100000 65761 ns/op 7296 B/op 139 allocs/op ```
1 parent e739b55 commit 2e15065

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,41 @@ func TestGet(t *testing.T) {
16161616
}
16171617
}
16181618

1619+
func BenchmarkGet(b *testing.B) {
1620+
storage := map[string]rest.Storage{}
1621+
simpleStorage := SimpleRESTStorage{
1622+
item: genericapitesting.Simple{
1623+
Other: "foo",
1624+
},
1625+
}
1626+
selfLinker := &setTestSelfLinker{
1627+
expectedSet: "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id",
1628+
name: "id",
1629+
namespace: "default",
1630+
}
1631+
storage["simple"] = &simpleStorage
1632+
handler := handleLinker(storage, selfLinker)
1633+
server := httptest.NewServer(handler)
1634+
defer server.Close()
1635+
1636+
u := server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id"
1637+
1638+
b.ResetTimer()
1639+
for i := 0; i < b.N; i++ {
1640+
resp, err := http.Get(u)
1641+
if err != nil {
1642+
b.Fatalf("unexpected error: %v", err)
1643+
}
1644+
if resp.StatusCode != http.StatusOK {
1645+
b.Fatalf("unexpected response: %#v", resp)
1646+
}
1647+
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
1648+
b.Fatalf("unable to read body")
1649+
}
1650+
}
1651+
b.StopTimer()
1652+
}
1653+
16191654
func TestGetCompression(t *testing.T) {
16201655
storage := map[string]rest.Storage{}
16211656
simpleStorage := SimpleRESTStorage{

0 commit comments

Comments
 (0)