MCPcopy
hub / github.com/grafana/dskit / BenchmarkMemberlistReceiveWithRingDesc

Function BenchmarkMemberlistReceiveWithRingDesc

ring/bench/ring_memberlist_test.go:62–107  ·  view source on GitHub ↗

Benchmark the memberlist receive path when it is being used as the ring backing store.

(b *testing.B)

Source from the content-addressed store, hash-verified

60
61// Benchmark the memberlist receive path when it is being used as the ring backing store.
62func BenchmarkMemberlistReceiveWithRingDesc(b *testing.B) {
63 c := ring.GetCodec()
64
65 var cfg memberlist.KVConfig
66 flagext.DefaultValues(&cfg)
67 cfg.TCPTransport = memberlist.TCPTransportConfig{}
68 cfg.Codecs = []codec.Codec{c}
69
70 mkv := memberlist.NewKV(cfg, log.NewNopLogger(), &dnsProviderMock{}, prometheus.NewPedanticRegistry())
71 require.NoError(b, services.StartAndAwaitRunning(context.Background(), mkv))
72 defer services.StopAndAwaitTerminated(context.Background(), mkv) //nolint:errcheck
73
74 // Build the initial ring state:
75 // - The ring isn't actually in use, so the fields such as address/zone are not important.
76 // - The number of keys in the store has no impact for this test, so simulate a single ring.
77 // - The number of instances in the ring does have a big impact.
78 const numInstances = 600
79 const numTokens = 128
80 initialDesc := ring.NewDesc()
81 {
82 for i := 0; i < numInstances; i++ {
83 tokens := generateUniqueTokens(i, numTokens)
84 initialDesc.AddIngester(fmt.Sprintf("instance-%d", i), "127.0.0.1", "zone", tokens, ring.ACTIVE, time.Now(), false, time.Time{}, nil)
85 }
86 // Send a single update to populate the store.
87 msg := encodeMessage(b, "ring", initialDesc)
88 mkv.NotifyMsg(msg)
89 }
90
91 // Ensure that each received message updates the ring.
92 testMsgs := make([][]byte, b.N)
93 for i := range testMsgs {
94 instance := initialDesc.Ingesters["instance-0"]
95 instance.Timestamp = initialDesc.Ingesters["instance-0"].RegisteredTimestamp + int64(i)
96
97 testDesc := ring.NewDesc()
98 testDesc.Ingesters["instance-0"] = instance
99 testMsgs[i] = encodeMessage(b, "ring", testDesc)
100 }
101
102 b.ResetTimer()
103
104 for i := 0; i < b.N; i++ {
105 mkv.NotifyMsg(testMsgs[i])
106 }
107}

Callers

nothing calls this directly

Calls 10

AddIngesterMethod · 0.95
NotifyMsgMethod · 0.95
GetCodecFunction · 0.92
DefaultValuesFunction · 0.92
NewKVFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
NewDescFunction · 0.92
generateUniqueTokensFunction · 0.85
encodeMessageFunction · 0.85

Tested by

no test coverage detected