Measures how fair the hash ring is to each endpoint. i.e. Of the possible hashes, how many will go to each endpoint. The lower the standard deviation the better.
(endpoints []string, hashesPerEndpoint int)
| 484 | // Measures how fair the hash ring is to each endpoint. |
| 485 | // i.e. Of the possible hashes, how many will go to each endpoint. The lower the standard deviation the better. |
| 486 | func measureStdDev(endpoints []string, hashesPerEndpoint int) float64 { |
| 487 | ch := newConsistentHashInternal(endpoints, hashesPerEndpoint).(*consistentHash) |
| 488 | ringOwnership := map[int]uint64{} |
| 489 | prevPartitionEndHash := uint64(0) |
| 490 | for i := 0; i < len(ch.hashRing); i++ { |
| 491 | endpointIndex := ch.hashRing[i].index |
| 492 | partitionEndHash := ch.hashRing[i].hash |
| 493 | ringOwnership[endpointIndex] += partitionEndHash - prevPartitionEndHash |
| 494 | prevPartitionEndHash = partitionEndHash |
| 495 | } |
| 496 | ringOwnership[ch.hashRing[0].index] += math.MaxUint64 - prevPartitionEndHash |
| 497 | return stdDeviation(ringOwnership) |
| 498 | } |
| 499 | |
| 500 | func stdDeviation(counters map[int]uint64) float64 { |
| 501 | sum := uint64(0) |
no test coverage detected
searching dependent graphs…