mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-25 06:31:35 +00:00
Add a benchmark for the discovery cache RoundTripper
This benchmark is intended to demonstrate a performance improvement gained by removing fsyncs. Refer to the below issue for more detail. https://github.com/kubernetes/kubernetes/issues/110753 Signed-off-by: Nic Cope <nicc@rk0n.org> Kubernetes-commit: eace46906512b99c23ad9635edc2ea055363a602
This commit is contained in:
parent
ec0f33729d
commit
76fccca0ea
@ -25,6 +25,8 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gregjones/httpcache/diskcache"
|
||||
"github.com/peterbourgon/diskv"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -40,6 +42,38 @@ func (rt *testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
|
||||
return rt.Response, rt.Err
|
||||
}
|
||||
|
||||
// NOTE(negz): We're adding a benchmark for an external dependency in order to
|
||||
// prove that one that will be added in a subsequent commit improves write
|
||||
// performance.
|
||||
func BenchmarkDiskCache(b *testing.B) {
|
||||
cacheDir, err := ioutil.TempDir("", "cache-rt")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(cacheDir)
|
||||
|
||||
d := diskv.New(diskv.Options{
|
||||
PathPerm: os.FileMode(0750),
|
||||
FilePerm: os.FileMode(0660),
|
||||
BasePath: cacheDir,
|
||||
TempDir: filepath.Join(cacheDir, ".diskv-temp"),
|
||||
})
|
||||
|
||||
k := "localhost:8080/apis/batch/v1.json"
|
||||
v, err := ioutil.ReadFile("../../testdata/apis/batch/v1.json")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
c := diskcache.NewWithDiskv(d)
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
c.Set(k, v)
|
||||
c.Get(k)
|
||||
c.Delete(k)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheRoundTripper(t *testing.T) {
|
||||
rt := &testRoundTripper{}
|
||||
cacheDir, err := ioutil.TempDir("", "cache-rt")
|
||||
|
Loading…
Reference in New Issue
Block a user