mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Fix hash order to generate more even distribution (#5247)
The problem in existing code was the following line ``` start := int(keyCrc%uint32(cardinality)) | 1 ``` A given a value of N cardinality the ending result because of the the bitwise '|' would lead to always higher affinity to odd sequences. As can be seen from the test cases that this can lead to many objects being allocated the same set of disks or atleast the first disk is an odd disk always. This introduces a performance problem for majority of the objects under concurrent load. Remove `| 1` to provide a more cleaner distribution and the new code will be. ``` start := int(keyCrc % uint32(cardinality)) ``` Thanks to Krishna Srinivas for pointing out the bitwise situation here.
This commit is contained in:
parent
6d7319380c
commit
d45a8784fc
@ -118,7 +118,7 @@ func hashOrder(key string, cardinality int) []int {
|
||||
nums := make([]int, cardinality)
|
||||
keyCrc := crc32.Checksum([]byte(key), crc32.IEEETable)
|
||||
|
||||
start := int(keyCrc%uint32(cardinality)) | 1
|
||||
start := int(keyCrc % uint32(cardinality))
|
||||
for i := 1; i <= cardinality; i++ {
|
||||
nums[i-1] = 1 + ((start + i) % cardinality)
|
||||
}
|
||||
|
@ -110,14 +110,14 @@ func TestHashOrder(t *testing.T) {
|
||||
}{
|
||||
// cases which should pass the test.
|
||||
// passing in valid object name.
|
||||
{"object", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||||
{"The Shining Script <v1>.pdf", []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
|
||||
{"object", []int{14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}},
|
||||
{"The Shining Script <v1>.pdf", []int{16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}},
|
||||
{"Cost Benefit Analysis (2009-2010).pptx", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||||
{"117Gn8rfHL2ACARPAhaFd0AGzic9pUbIA/5OCn5A", []int{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2}},
|
||||
{"SHØRT", []int{11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
|
||||
{"There are far too many object names, and far too few bucket names!", []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||||
{"a/b/c/", []int{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2}},
|
||||
{"/a/b/c", []int{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6}},
|
||||
{"/a/b/c", []int{6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5}},
|
||||
{string([]byte{0xff, 0xfe, 0xfd}), []int{15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user