public void MatchServersToFixedBucket() { try { int targetBuckets = 3; int serverCount = 40; int minDbCount = 10; int maxDbCount = 500; Random rnd = new Random(); string tmpFile = string.Empty; MultiDbData multiData; try { for (int i = 0; i < 100; i++) { targetBuckets = rnd.Next(2, 90); serverCount = rnd.Next(targetBuckets + 1, 300); minDbCount = rnd.Next(10, 150); maxDbCount = rnd.Next(minDbCount + 1, 500); int[] matrix; (tmpFile, multiData) = CreateRandomizedMultiDbData(serverCount, minDbCount, maxDbCount, out matrix); //The real work var buckets = Concurrency.RecombineServersToFixedBucketCount(multiData, targetBuckets); //Numbers for comparisons var flattened = Concurrency.ConcurrencyByServer(multiData); var idealBucket = Math.Ceiling((double)flattened.Sum(c => c.Count()) / (double)targetBuckets); int maxBucket = flattened.Where(c => c.Count() <= idealBucket).Max(c => c.Count()); //exclude the buckets that were already above the ideal int medianBucket = flattened.OrderBy(c => c.Count()).ToList()[(flattened.Count() / 2) + 1].Count(); string message = $"Buckets: {targetBuckets}; Servers: {serverCount}; Matrix: {string.Join(",", matrix)}"; Assert.AreEqual(targetBuckets, buckets.Count(), message); Assert.IsTrue(buckets.Max(c => c.Count()) < maxBucket + (idealBucket * 1.2), message); var str = Concurrency.ConvertBucketsToConfigLines(buckets); if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } } finally { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } } catch (OutOfMemoryException) { //GitHub actions sometimes will run out of memory running this test! } }
public void DbOverrideConcurrencyByServerTest() { string tmpFile = string.Empty; MultiDbData multiData; try { (tmpFile, multiData) = GetMultiDbData(); var output = Concurrency.ConcurrencyByServer(multiData); Assert.AreEqual(449, output[0].Count()); Assert.AreEqual(5, output.Count()); Assert.AreEqual(96, output.Last().Count()); } finally { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } }
public void MatchDefinedServersToFixedBucket(int targetBuckets, int serverCount, int[] dbsPerServer) { string tmpFile = string.Empty; MultiDbData multiData; try { (tmpFile, multiData) = CreateDefinedMultiDbData(serverCount, dbsPerServer); //The real work var buckets = Concurrency.RecombineServersToFixedBucketCount(multiData, targetBuckets); //Numbers for comparisons var flattened = Concurrency.ConcurrencyByServer(multiData); var idealBucket = Math.Ceiling((double)flattened.Sum(c => c.Count()) / (double)targetBuckets); int maxBucket = flattened.Where(c => c.Count() <= idealBucket).Max(c => c.Count()); //exclude the buckets that were already above the ideal int medianBucket = flattened.OrderBy(c => c.Count()).ToList()[(flattened.Count() / 2) + 1].Count(); string message = $"Buckets: {targetBuckets}; Servers: {serverCount}; Matrix: {string.Join(",", dbsPerServer)}"; Assert.AreEqual(targetBuckets, buckets.Count(), message); Assert.IsTrue(buckets.Max(c => c.Count()) < maxBucket + idealBucket + (idealBucket * 1.2), message); var str = Concurrency.ConvertBucketsToConfigLines(buckets); if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } finally { if (File.Exists(tmpFile)) { File.Delete(tmpFile); } } }