MCPcopy Create free account
hub / github.com/cortexproject/cortex / BenchmarkHATracker_syncKVStoreToLocalMap

Function BenchmarkHATracker_syncKVStoreToLocalMap

pkg/ha/ha_tracker_test.go:917–958  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

915}
916
917func BenchmarkHATracker_syncKVStoreToLocalMap(b *testing.B) {
918 keyCounts := []int{100, 1000, 10000}
919
920 for _, count := range keyCounts {
921 b.Run(fmt.Sprintf("keys=%d", count), func(b *testing.B) {
922 ctx := context.Background()
923
924 codec := GetReplicaDescCodec()
925 kvStore, closer := consul.NewInMemoryClient(codec, log.NewNopLogger(), nil)
926 b.Cleanup(func() { assert.NoError(b, closer.Close()) })
927
928 mockKV := kv.PrefixClient(kvStore, "prefix")
929
930 for i := range count {
931 key := fmt.Sprintf("user-%d/cluster-%d", i%100, i)
932 desc := &ReplicaDesc{
933 Replica: fmt.Sprintf("replica-%d", i),
934 ReceivedAt: timestamp.FromTime(time.Now()),
935 }
936 err := mockKV.CAS(ctx, key, func(_ any) (any, bool, error) {
937 return desc, true, nil
938 })
939 require.NoError(b, err)
940 }
941
942 cfg := HATrackerConfig{
943 EnableHATracker: true,
944 EnableStartupSync: true,
945 KVStore: kv.Config{Mock: mockKV},
946 }
947 tracker, _ := NewHATracker(cfg, trackerLimits{}, haTrackerStatusConfig, nil, "bench", log.NewNopLogger())
948
949 b.ReportAllocs()
950 for b.Loop() {
951 err := tracker.syncKVStoreToLocalMap(ctx)
952 if err != nil {
953 b.Fatal(err)
954 }
955 }
956 })
957 }
958}
959
960func TestHATracker_CacheWarmupOnStart(t *testing.T) {
961 t.Parallel()

Callers

nothing calls this directly

Calls 9

syncKVStoreToLocalMapMethod · 0.95
NewInMemoryClientFunction · 0.92
PrefixClientFunction · 0.92
GetReplicaDescCodecFunction · 0.85
NewHATrackerFunction · 0.85
LoopMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.65
CASMethod · 0.65

Tested by

no test coverage detected