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

Function BenchmarkRing_Get_OneZoneLeaving

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

Source from the content-addressed store, hash-verified

3792}
3793
3794func BenchmarkRing_Get_OneZoneLeaving(b *testing.B) {
3795 // This benchmark tests a pathological case in the ring. If an entire zone is "LEAVING", we'll have to
3796 // look at every instance in that zone, extending the replication set, to try to find one we can use for
3797 // our operation. Previous versions of the ring would examine every single token in an attempt to find a
3798 // usable host in the zone with all instances "LEAVING", resulting in poor performance.
3799 const (
3800 instances = 1200
3801 zones = 4
3802 )
3803
3804 for _, oneZoneLeaving := range []bool{true, false} {
3805 b.Run(fmt.Sprintf("one zone leaving = %t", oneZoneLeaving), func(b *testing.B) {
3806 ringDesc := &Desc{Ingesters: generateRingInstances(initTokenGenerator(b), instances, zones, numTokens)}
3807
3808 if oneZoneLeaving {
3809 // Go through the last zone and set the instances as leaving.
3810 for id, inst := range ringDesc.Ingesters {
3811 if inst.Zone == "zone-2" {
3812 inst.State = LEAVING
3813 ringDesc.Ingesters[id] = inst
3814 }
3815 }
3816 }
3817
3818 ring := newRingForTesting(Config{
3819 HeartbeatTimeout: time.Hour,
3820 ZoneAwarenessEnabled: true,
3821 SubringCacheDisabled: true,
3822 ReplicationFactor: zones,
3823 }, true)
3824
3825 ring.setRingStateFromDesc(ringDesc, false, false, false)
3826 ring.strategy = NewIgnoreUnhealthyInstancesReplicationStrategy()
3827
3828 buf, bufHosts, bufZones := MakeBuffersForGet()
3829 r := rand.New(rand.NewSource(time.Now().UnixNano()))
3830
3831 expectedInstances := zones
3832 if oneZoneLeaving {
3833 expectedInstances = zones - 1
3834 }
3835
3836 b.ResetTimer()
3837 b.ReportAllocs()
3838 for n := 0; n < b.N; n++ {
3839 set, err := ring.Get(r.Uint32(), Write, buf, bufHosts, bufZones)
3840 if err != nil {
3841 b.Fatal(err)
3842 }
3843 if actualInstances := len(set.Instances); actualInstances != expectedInstances {
3844 b.Fatalf("expected %d instances, got %d", expectedInstances, actualInstances)
3845 }
3846 }
3847 })
3848 }
3849}
3850
3851func TestRing_Get_NoMemoryAllocations(t *testing.T) {

Callers

nothing calls this directly

Calls 10

generateRingInstancesFunction · 0.85
initTokenGeneratorFunction · 0.85
newRingForTestingFunction · 0.85
MakeBuffersForGetFunction · 0.85
RunMethod · 0.80
setRingStateFromDescMethod · 0.80
FatalMethod · 0.80
FatalfMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected