Example #1
0
        public void It_Should_Recommend_Correct_Throughput_Value_For_Growth_Rate(int partitionCount, double maximumRequestUnitValue, double growthRate, int expectedThroughput)
        {
            // act
            var result = CosmosDbThroughputHelper.GetRecommendedThroughput(partitionCount, maximumRequestUnitValue,
                                                                           AbstractCosmosDbPersistenceThroughputMonitor.DefaultMinimumThroughput, AbstractCosmosDbPersistenceThroughputMonitor.DefaultMaximumThroughput, growthRate);

            // assert
            Assert.Equal(expectedThroughput, result);
        }
Example #2
0
        private async Task PerformUpdateThroughputAsync(string correlationId, string collectionName, IEnumerable <Metric> throughputMetrics)
        {
            if (throughputMetrics == null || !throughputMetrics.Any())
            {
                _logger.Warn(correlationId, $"PerformUpdateThroughputAsync: Skip to update throughput of collection '{collectionName}', because of missing throughput metrics.");
                return;
            }

            // 1. Group throughput metrics by name
            var groupedMetricsData = throughputMetrics.GroupBy(metric => metric.Name.Value);

            var groupedMetrics = groupedMetricsData.FirstOrDefault();

            if (groupedMetrics == null)
            {
                _logger.Warn(correlationId, $"PerformUpdateThroughputAsync: Unable to group throughput metrics for collection '{collectionName}'.");
                return;
            }

            // 2. Retrieve maximum Request Unit value and partition count
            var partitionCount          = groupedMetrics.Count();
            var maximumRequestUnitValue = 0.0;

            foreach (var metric in groupedMetrics)
            {
                if (metric.MetricValues == null)
                {
                    continue;
                }

                maximumRequestUnitValue = Math.Max(maximumRequestUnitValue, metric.MetricValues.Max(metricValue => metricValue.Maximum) ?? 0);
            }

            var recommendedThroughput = CosmosDbThroughputHelper.GetRecommendedThroughput(partitionCount, maximumRequestUnitValue, MinimumThroughput, MaximumThroughput, GrowthRate);

            _logger.Info(correlationId, $"PerformUpdateThroughputAsync: Recommended throughput: '{recommendedThroughput}' for collection '{collectionName}' based on '{groupedMetrics.Key}': '{maximumRequestUnitValue}' with partition count: '{partitionCount}' and a growth rate of '{GrowthRate}'┬.");

            // 3. Perform updating throughput of CosmosDB collection by recommended value
            await PerformUpdateThroughputAsync(correlationId, collectionName, recommendedThroughput);
        }