(b *testing.B, g TokenGenerator, numInstances, numZones, numTokens int, updateTokens bool)
| 120 | } |
| 121 | |
| 122 | func benchmarkUpdateRingState(b *testing.B, g TokenGenerator, numInstances, numZones, numTokens int, updateTokens bool) { |
| 123 | cfg := Config{ |
| 124 | KVStore: kv.Config{}, |
| 125 | HeartbeatTimeout: 0, // get healthy stats |
| 126 | ReplicationFactor: 3, |
| 127 | ZoneAwarenessEnabled: true, |
| 128 | } |
| 129 | |
| 130 | // create the ring to set up metrics, but do not start |
| 131 | registry := prometheus.NewRegistry() |
| 132 | ring, err := NewWithStoreClientAndStrategy(cfg, testRingName, testRingKey, &MockClient{}, NewDefaultReplicationStrategy(), registry, log.NewNopLogger()) |
| 133 | require.NoError(b, err) |
| 134 | |
| 135 | // Make a random ring with N instances, and M tokens per ingests |
| 136 | // Also make a copy with different timestamps and one with different tokens |
| 137 | desc := NewDesc() |
| 138 | otherDesc := NewDesc() |
| 139 | for i := range numInstances { |
| 140 | id := fmt.Sprintf("%d", i) |
| 141 | tokens := g.GenerateTokens(desc, id, "zone", numTokens, true) |
| 142 | now := time.Now() |
| 143 | desc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, ACTIVE, now) |
| 144 | if updateTokens { |
| 145 | otherTokens := g.GenerateTokens(otherDesc, id, "zone", numTokens, true) |
| 146 | otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), otherTokens, ACTIVE, now) |
| 147 | } else { |
| 148 | otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, JOINING, now) |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if updateTokens { |
| 153 | require.Equal(b, Different, desc.RingCompare(otherDesc)) |
| 154 | } else { |
| 155 | require.Equal(b, EqualButStatesAndTimestamps, desc.RingCompare(otherDesc)) |
| 156 | } |
| 157 | |
| 158 | flipFlop := true |
| 159 | |
| 160 | for b.Loop() { |
| 161 | if flipFlop { |
| 162 | ring.updateRingState(desc) |
| 163 | } else { |
| 164 | ring.updateRingState(otherDesc) |
| 165 | } |
| 166 | flipFlop = !flipFlop |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func TestDoBatchZeroInstances(t *testing.T) { |
| 171 | ctx := context.Background() |
no test coverage detected