Last active
July 31, 2017 18:04
-
-
Save redbo/4cd29975b61445742fd0ddeb3ed9d550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/troubling/hummingbird/common/ring" | |
) | |
func main() { | |
ring, err := ring.LoadRing(os.Args[1], "prefix", "suffix") | |
if err != nil { | |
fmt.Println("ERR", err) | |
return | |
} | |
replicas := int(ring.ReplicaCount()) | |
devs := ring.AllDevices() | |
totalWeight := float64(0) | |
devPartitions := make([]map[uint64]bool, len(devs)) | |
for i, dev := range devs { | |
totalWeight += dev.Weight | |
devPartitions[i] = make(map[uint64]bool) | |
} | |
partCounts := make([]int64, len(devs)) | |
for part := uint64(0); part < ring.PartitionCount(); part++ { | |
for _, node := range ring.GetNodes(part) { | |
devPartitions[node.Id][part] = true | |
partCounts[node.Id]++ | |
} | |
} | |
for i, dev := range devs { | |
want := int64((dev.Weight / totalWeight) * float64(ring.PartitionCount()) * float64(replicas)) | |
diff := int64(0) | |
if partCounts[i] > want { | |
diff = partCounts[i] - want | |
} else { | |
diff = want - partCounts[i] | |
} | |
if (float64(diff) / float64(want)) > 0.01 { | |
fmt.Println("Device", dev.Id, "partition count >1% off its want:", partCounts[i], "vs", want) | |
} | |
} | |
totalPairings := int64(0) | |
for i, dev1 := range devs { | |
for _, dev2 := range devs[i:] { | |
if dev1.Id != dev2.Id { | |
totalPairings += partCounts[dev1.Id] * partCounts[dev2.Id] | |
} | |
} | |
} | |
totalSharesRequired := ring.PartitionCount() * (ring.ReplicaCount() * ((ring.ReplicaCount() - 1) / 2)) | |
if ring.ReplicaCount() == 2 { | |
totalSharesRequired = ring.PartitionCount() | |
} | |
for i, dev1 := range devs { | |
for _, dev2 := range devs[i:] { | |
if dev1.Id != dev2.Id { | |
shouldShare := | |
int64(float64(partCounts[dev1.Id]*partCounts[dev2.Id]) * | |
(float64(totalSharesRequired) / float64(totalPairings))) | |
shared := int64(0) | |
for part := range devPartitions[dev1.Id] { | |
if devPartitions[dev2.Id][part] { | |
shared++ | |
} | |
} | |
diff := int64(0) | |
if shared > shouldShare { | |
diff = shared - shouldShare | |
} else { | |
diff = shouldShare - shared | |
} | |
if (float64(diff) / float64(shouldShare)) > 0.01 { | |
fmt.Println(dev1.Id, "and", dev2.Id, "should share", shouldShare, "partitions, but share", shared) | |
} | |
} | |
} | |
} | |
regions := make(map[int]bool) | |
zones := make(map[int]bool) | |
ips := make(map[string]bool) | |
devices := make(map[string]bool) | |
for _, dev := range devs { | |
regions[dev.Region] = true | |
ips[dev.Ip] = true | |
zones[dev.Zone] = true | |
devices[fmt.Sprintf("%s:%s", dev.Ip, dev.Device)] = true | |
} | |
for part := uint64(0); part < ring.PartitionCount(); part++ { | |
partRegions := make(map[int]bool) | |
partZones := make(map[int]bool) | |
partIps := make(map[string]bool) | |
partDevices := make(map[string]bool) | |
for _, dev := range ring.GetNodes(part) { | |
partRegions[dev.Region] = true | |
partZones[dev.Zone] = true | |
partIps[dev.Ip] = true | |
partDevices[fmt.Sprintf("%s:%s", dev.Ip, dev.Device)] = true | |
} | |
if len(partRegions) < len(regions) && len(partRegions) < replicas { | |
fmt.Println("Partition", part, "doesn't use all available regions.") | |
} | |
if len(partZones) < len(zones) && len(partZones) < replicas { | |
fmt.Println("Partition", part, "doesn't use all available zones.") | |
} | |
if len(partIps) < len(ips) && len(partIps) < replicas { | |
fmt.Println("Partition", part, "doesn't use all available IPs.") | |
} | |
if len(partDevices) < len(devices) && len(partDevices) < replicas { | |
fmt.Println("Partition", part, "doesn't use all available devices.") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment