From 58fde6697745c3e667fbea481baae39c3ea6abfc Mon Sep 17 00:00:00 2001 From: Forrest Marshall Date: Thu, 15 Aug 2024 15:25:33 -0700 Subject: [PATCH 1/2] improve max nodes benchmark --- Makefile | 2 +- lib/cache/cache_test.go | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 99f1cf6acb6f3..ed5ba0f583d35 100644 --- a/Makefile +++ b/Makefile @@ -885,7 +885,7 @@ endif # todo: Use gotestsum when it is compatible with benchmark output. Currently will consider all benchmarks failed. .PHONY: test-go-bench test-go-bench: PACKAGES = $(shell grep --exclude-dir api --include "*_test.go" -lr testing.B . | xargs dirname | xargs go list | sort -u) -test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot|^BenchmarkGetMaxNodes$$" +test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot$$" test-go-bench: | $(TEST_LOG_DIR) go test -run ^$$ -bench . -skip $(BENCHMARK_SKIP_PATTERN) -benchtime 1x $(PACKAGES) \ | tee $(TEST_LOG_DIR)/bench.txt diff --git a/lib/cache/cache_test.go b/lib/cache/cache_test.go index c733695edeab1..1161aa27205ac 100644 --- a/lib/cache/cache_test.go +++ b/lib/cache/cache_test.go @@ -925,7 +925,7 @@ cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz BenchmarkGetMaxNodes-16 1 1029199093 ns/op */ func BenchmarkGetMaxNodes(b *testing.B) { - benchGetNodes(b, backend.DefaultRangeLimit) + benchGetNodes(b, 1_000_000) } func benchGetNodes(b *testing.B, nodeCount int) { @@ -933,18 +933,32 @@ func benchGetNodes(b *testing.B, nodeCount int) { require.NoError(b, err) defer p.Close() - ctx := context.Background() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - for i := 0; i < nodeCount; i++ { - server := suite.NewServer(types.KindNode, uuid.New().String(), "127.0.0.1:2022", apidefaults.Namespace) - _, err := p.presenceS.UpsertNode(ctx, server) - require.NoError(b, err) + createErr := make(chan error, 1) + go func() { + for i := 0; i < nodeCount; i++ { + server := suite.NewServer(types.KindNode, uuid.New().String(), "127.0.0.1:2022", apidefaults.Namespace) + _, err := p.presenceS.UpsertNode(ctx, server) + if err != nil { + createErr <- err + return + } + } + }() + + timeout := time.After(time.Second * 90) + + for i := 0; i < nodeCount; i++ { select { case event := <-p.eventsC: require.Equal(b, EventProcessed, event.Type) - case <-time.After(200 * time.Millisecond): - b.Fatalf("timeout waiting for event, iteration=%d", i) + case err := <-createErr: + b.Fatalf("failed to create node: %v", err) + case <-timeout: + b.Fatalf("timeout waiting for event, progress=%d", i) } } From 455cb9aa94b6dec92fbf78ccdf3aef4050828f7e Mon Sep 17 00:00:00 2001 From: Forrest <30576607+fspmarshall@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:31:13 -0700 Subject: [PATCH 2/2] Update Makefile Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ed5ba0f583d35..da61cda99f4bd 100644 --- a/Makefile +++ b/Makefile @@ -885,7 +885,7 @@ endif # todo: Use gotestsum when it is compatible with benchmark output. Currently will consider all benchmarks failed. .PHONY: test-go-bench test-go-bench: PACKAGES = $(shell grep --exclude-dir api --include "*_test.go" -lr testing.B . | xargs dirname | xargs go list | sort -u) -test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot$$" +test-go-bench: BENCHMARK_SKIP_PATTERN = "^BenchmarkRoot" test-go-bench: | $(TEST_LOG_DIR) go test -run ^$$ -bench . -skip $(BENCHMARK_SKIP_PATTERN) -benchtime 1x $(PACKAGES) \ | tee $(TEST_LOG_DIR)/bench.txt