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

Function BenchmarkRing_Get

ring/ring_test.go:3737–3792  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

3735}
3736
3737func BenchmarkRing_Get(b *testing.B) {
3738 benchCases := map[string]struct {
3739 numInstances int
3740 numZones int
3741 replicationFactor int
3742 }{
3743 "with zone awareness": {
3744 numInstances: 99,
3745 numZones: 3,
3746 replicationFactor: 3,
3747 },
3748 "one excluded zone": {
3749 numInstances: 66,
3750 numZones: 2,
3751 replicationFactor: 3,
3752 },
3753 "without zone awareness": {
3754 numInstances: 3,
3755 numZones: 1,
3756 replicationFactor: 3,
3757 },
3758 "without zone awareness, not enough instances": {
3759 numInstances: 2,
3760 numZones: 1,
3761 replicationFactor: 3,
3762 },
3763 }
3764
3765 for benchName, benchCase := range benchCases {
3766 // Initialise the ring.
3767 ringDesc := &Desc{Ingesters: generateRingInstances(initTokenGenerator(b), benchCase.numInstances, benchCase.numZones, numTokens)}
3768 ring := newRingForTesting(Config{
3769 HeartbeatTimeout: time.Hour,
3770 ZoneAwarenessEnabled: benchCase.numZones > 1,
3771 SubringCacheDisabled: true,
3772 ReplicationFactor: benchCase.replicationFactor,
3773 }, true)
3774 ring.setRingStateFromDesc(ringDesc, false, false, false)
3775
3776 buf, bufHosts, bufZones := MakeBuffersForGet()
3777 r := rand.New(rand.NewSource(time.Now().UnixNano()))
3778
3779 expectedInstances := min(benchCase.numInstances, benchCase.replicationFactor)
3780 if ring.cfg.ZoneAwarenessEnabled {
3781 expectedInstances = min(benchCase.numZones, benchCase.replicationFactor)
3782 }
3783
3784 b.Run(benchName, func(b *testing.B) {
3785 for n := 0; n < b.N; n++ {
3786 set, err := ring.Get(r.Uint32(), Write, buf, bufHosts, bufZones)
3787 assert.NoError(b, err)
3788 assert.Equal(b, expectedInstances, len(set.Instances))
3789 }
3790 })
3791 }
3792}
3793
3794func BenchmarkRing_Get_OneZoneLeaving(b *testing.B) {

Callers

nothing calls this directly

Calls 8

generateRingInstancesFunction · 0.85
initTokenGeneratorFunction · 0.85
newRingForTestingFunction · 0.85
MakeBuffersForGetFunction · 0.85
setRingStateFromDescMethod · 0.80
RunMethod · 0.80
GetMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected