From c6dceb1265f02439c85d6a814cec8b8db9518ab7 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 12 May 2023 15:10:04 +0200 Subject: [PATCH] Add LoadData Benchmark --- pkg/archive/fsBackend_test.go | 50 ++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/pkg/archive/fsBackend_test.go b/pkg/archive/fsBackend_test.go index 8e16e1b..dd6883c 100644 --- a/pkg/archive/fsBackend_test.go +++ b/pkg/archive/fsBackend_test.go @@ -7,9 +7,11 @@ package archive import ( "encoding/json" "fmt" + "path/filepath" "testing" "time" + "github.com/ClusterCockpit/cc-backend/internal/util" "github.com/ClusterCockpit/cc-backend/pkg/schema" ) @@ -106,7 +108,7 @@ func TestLoadJobMeta(t *testing.T) { func TestLoadJobData(t *testing.T) { var fsa FsArchive - _, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}")) + _, err := fsa.Init(json.RawMessage("{\"path\": \"testdata/archive\"}")) if err != nil { t.Fatal(err) } @@ -121,8 +123,8 @@ func TestLoadJobData(t *testing.T) { t.Fatal(err) } - for name, scopes := range data { - fmt.Printf("Metric name: %s\n", name) + for _, scopes := range data { + // fmt.Printf("Metric name: %s\n", name) if _, exists := scopes[schema.MetricScopeNode]; !exists { t.Fail() @@ -130,6 +132,48 @@ func TestLoadJobData(t *testing.T) { } } +func BenchmarkLoadJobData(b *testing.B) { + + tmpdir := b.TempDir() + jobarchive := filepath.Join(tmpdir, "job-archive") + util.CopyDir("./testdata/archive/", jobarchive) + archiveCfg := fmt.Sprintf("{\"path\": \"%s\"}", jobarchive) + + var fsa FsArchive + fsa.Init(json.RawMessage(archiveCfg)) + + jobIn := schema.Job{BaseJob: schema.JobDefaults} + jobIn.StartTime = time.Unix(1608923076, 0) + jobIn.JobID = 1403244 + jobIn.Cluster = "emmy" + + b.ResetTimer() + for i := 0; i < b.N; i++ { + fsa.LoadJobData(&jobIn) + } +} + +func BenchmarkLoadJobDataCompressed(b *testing.B) { + + tmpdir := b.TempDir() + jobarchive := filepath.Join(tmpdir, "job-archive") + util.CopyDir("./testdata/archive/", jobarchive) + archiveCfg := fmt.Sprintf("{\"path\": \"%s\"}", jobarchive) + + var fsa FsArchive + fsa.Init(json.RawMessage(archiveCfg)) + + jobIn := schema.Job{BaseJob: schema.JobDefaults} + jobIn.StartTime = time.Unix(1608923076, 0) + jobIn.JobID = 1403244 + jobIn.Cluster = "emmy" + + b.ResetTimer() + for i := 0; i < b.N; i++ { + fsa.LoadJobData(&jobIn) + } +} + func TestLoadCluster(t *testing.T) { var fsa FsArchive _, err := fsa.Init(json.RawMessage("{\"path\":\"testdata/archive\"}"))