Skip to content

Commit

Permalink
improve max nodes benchmark (#45545) (#45850)
Browse files Browse the repository at this point in the history
* improve max nodes benchmark

* Update Makefile



---------

Co-authored-by: rosstimothy <[email protected]>
  • Loading branch information
fspmarshall and rosstimothy authored Aug 26, 2024
1 parent e5c0f0e commit bf3b841
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,26 +925,40 @@ 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) {
p, err := newPack(b.TempDir(), ForAuth, memoryBackend(true))
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)
}
}

Expand Down

0 comments on commit bf3b841

Please sign in to comment.