(b *testing.B, numInstances, numTokens int, updateTokens bool)
| 137 | } |
| 138 | |
| 139 | func benchmarkUpdateRingState(b *testing.B, numInstances, numTokens int, updateTokens bool) { |
| 140 | cfg := Config{ |
| 141 | KVStore: kv.Config{}, |
| 142 | HeartbeatTimeout: time.Hour, // long timeout to get healthy stats |
| 143 | ReplicationFactor: 3, |
| 144 | ZoneAwarenessEnabled: true, |
| 145 | } |
| 146 | |
| 147 | gen := initTokenGenerator(b) |
| 148 | |
| 149 | // create the ring to set up metrics, but do not start |
| 150 | registry := prometheus.NewRegistry() |
| 151 | ring, err := NewWithStoreClientAndStrategy(cfg, testRingName, testRingKey, nil, NewDefaultReplicationStrategy(), registry, log.NewNopLogger()) |
| 152 | require.NoError(b, err) |
| 153 | |
| 154 | // Make a random ring with N instances, and M tokens per ingests |
| 155 | // Also make a copy with different timestamps and one with different tokens |
| 156 | desc := NewDesc() |
| 157 | otherDesc := NewDesc() |
| 158 | takenTokens := []uint32{} |
| 159 | otherTakenTokens := []uint32{} |
| 160 | for i := 0; i < numInstances; i++ { |
| 161 | tokens := gen.GenerateTokens(numTokens, takenTokens) |
| 162 | takenTokens = append(takenTokens, tokens...) |
| 163 | now := time.Now() |
| 164 | zeroTime := time.Time{} |
| 165 | id := fmt.Sprintf("%d", i) |
| 166 | desc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, ACTIVE, now, false, zeroTime, nil) |
| 167 | if updateTokens { |
| 168 | otherTokens := gen.GenerateTokens(numTokens, otherTakenTokens) |
| 169 | otherTakenTokens = append(otherTakenTokens, otherTokens...) |
| 170 | otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), otherTokens, ACTIVE, now, false, zeroTime, nil) |
| 171 | } else { |
| 172 | otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, JOINING, now, false, zeroTime, nil) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | if updateTokens { |
| 177 | require.Equal(b, Different, desc.RingCompare(otherDesc)) |
| 178 | } else { |
| 179 | require.Equal(b, EqualButStatesAndTimestamps, desc.RingCompare(otherDesc)) |
| 180 | } |
| 181 | |
| 182 | flipFlop := true |
| 183 | b.ResetTimer() |
| 184 | for n := 0; n < b.N; n++ { |
| 185 | if flipFlop { |
| 186 | ring.updateRingState(desc) |
| 187 | } else { |
| 188 | ring.updateRingState(otherDesc) |
| 189 | } |
| 190 | flipFlop = !flipFlop |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | func TestDoBatchZeroInstances(t *testing.T) { |
| 195 | ctx := context.Background() |
no test coverage detected