diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/IExecutionStrategy.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/IExecutionStrategy.cs index 865a006eab..b18fc34dc7 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/IExecutionStrategy.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/IExecutionStrategy.cs @@ -10,16 +10,15 @@ namespace CosmosBenchmark internal interface IExecutionStrategy { public static IExecutionStrategy StartNew( - BenchmarkConfig config, Func benchmarkOperation) { return new ParallelExecutionStrategy(benchmarkOperation); } public Task ExecuteAsync( + BenchmarkConfig benchmarkConfig, int serialExecutorConcurrency, int serialExecutorIterationCount, - bool traceFalures, double warmupFraction); } diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/ParallelExecutionStrategy.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/ParallelExecutionStrategy.cs index cc7d71d5fa..e5dc7bb58d 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/ParallelExecutionStrategy.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Fx/ParallelExecutionStrategy.cs @@ -25,9 +25,9 @@ public ParallelExecutionStrategy( } public async Task ExecuteAsync( + BenchmarkConfig benchmarkConfig, int serialExecutorConcurrency, int serialExecutorIterationCount, - bool traceFailures, double warmupFraction) { IExecutor warmupExecutor = new SerialOperationExecutor( @@ -36,7 +36,7 @@ public async Task ExecuteAsync( await warmupExecutor.ExecuteAsync( (int)(serialExecutorIterationCount * warmupFraction), isWarmup: true, - traceFailures: traceFailures, + traceFailures: benchmarkConfig.TraceFailures, completionCallback: () => { }); IExecutor[] executors = new IExecutor[serialExecutorConcurrency]; @@ -53,14 +53,18 @@ await warmupExecutor.ExecuteAsync( _ = executors[i].ExecuteAsync( iterationCount: serialExecutorIterationCount, isWarmup: false, - traceFailures: traceFailures, + traceFailures: benchmarkConfig.TraceFailures, completionCallback: () => Interlocked.Decrement(ref this.pendingExecutorCount)); } - return await this.LogOutputStats(executors); + return await this.LogOutputStats( + benchmarkConfig, + executors); } - private async Task LogOutputStats(IExecutor[] executors) + private async Task LogOutputStats( + BenchmarkConfig benchmarkConfig, + IExecutor[] executors) { const int outputLoopDelayInSeconds = 1; IList perLoopCounters = new List(); @@ -112,7 +116,9 @@ private async Task LogOutputStats(IExecutor[] executors) IEnumerable exceptFirst5 = perLoopCounters.Skip(5); int[] summaryCounters = exceptFirst5.Take(exceptFirst5.Count() - 5).OrderByDescending(e => e).ToArray(); - RunSummary runSummary = new RunSummary(); + RunSummary runSummary = new RunSummary( + benchmarkConfig, + executors.Length); if (summaryCounters.Length > 10) { diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs index e49d19fc6b..99131262d7 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/Program.cs @@ -136,8 +136,8 @@ private async Task ExecuteAsync(BenchmarkConfig config) Program.ClearCoreSdkListeners(); } - IExecutionStrategy execution = IExecutionStrategy.StartNew(config, benchmarkOperationFactory); - runSummary = await execution.ExecuteAsync(taskCount, opsPerTask, config.TraceFailures, 0.01); + IExecutionStrategy execution = IExecutionStrategy.StartNew(benchmarkOperationFactory); + runSummary = await execution.ExecuteAsync(config, taskCount, opsPerTask, 0.01); } if (config.CleanupOnFinish) @@ -146,24 +146,6 @@ private async Task ExecuteAsync(BenchmarkConfig config) await database.DeleteStreamAsync(); } - runSummary.WorkloadType = config.WorkloadType; - runSummary.id = $"{DateTime.UtcNow:yyyy-MM-dd:HH-mm}-{config.CommitId}"; - runSummary.Commit = config.CommitId; - runSummary.CommitDate = config.CommitDate; - runSummary.CommitTime = config.CommitTime; - - runSummary.Date = DateTime.UtcNow.ToString("yyyy-MM-dd"); - runSummary.Time = DateTime.UtcNow.ToString("HH-mm"); - runSummary.BranchName = config.BranchName; - runSummary.TotalOps = config.ItemCount; - runSummary.Concurrency = taskCount; - runSummary.Database = config.Database; - runSummary.Container = config.Container; - runSummary.AccountName = config.EndPoint; - runSummary.pk = config.ResultsPartitionKeyValue; - runSummary.MaxTcpConnectionsPerEndpoint = config.MaxTcpConnectionsPerEndpoint; - runSummary.MaxRequestsPerTcpConnection = config.MaxRequestsPerTcpConnection; - string consistencyLevel = config.ConsistencyLevel; if (string.IsNullOrWhiteSpace(consistencyLevel)) { diff --git a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/RunSummary.cs b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/RunSummary.cs index 5ec49f8cbb..64fe8f97d9 100644 --- a/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/RunSummary.cs +++ b/Microsoft.Azure.Cosmos.Samples/Tools/Benchmark/RunSummary.cs @@ -10,28 +10,42 @@ namespace CosmosBenchmark public class RunSummary { - public string pk { get; set; } + public RunSummary( + BenchmarkConfig benchmarkConfig, + int concurrency) + { + this.BenchmarkConfig = benchmarkConfig ?? throw new ArgumentNullException(nameof(benchmarkConfig)); + DateTime utcNow = DateTime.UtcNow; + this.id = $"{utcNow:yyyy-MM-dd:HH-mm}-{benchmarkConfig.CommitId}"; + this.Date = utcNow.ToString("yyyy-MM-dd"); + this.Time = utcNow.ToString("HH-mm"); + this.Concurrency = concurrency; + } - public string id { get; set; } - public string Commit { get; set; } - public string CommitDate { get; set; } - public string CommitTime { get; set; } + public string pk => this.BenchmarkConfig.ResultsPartitionKeyValue; + + public string id { get; } + public string Commit => this.BenchmarkConfig.CommitId; + public string CommitDate => this.BenchmarkConfig.CommitDate; + public string CommitTime => this.BenchmarkConfig.CommitTime; public string Remarks { get; set; } - public string Date { get; set; } - public string Time { get; set; } + public string Date { get; } + public string Time { get; } - public string WorkloadType { get; set; } - public string BranchName { get; set; } - public string AccountName { get; set; } - public string Database { get; set; } - public string Container { get; set; } + public BenchmarkConfig BenchmarkConfig { get; } + public string WorkloadType => this.BenchmarkConfig.WorkloadType; + public string BranchName => this.BenchmarkConfig.BranchName; + public string AccountName => this.BenchmarkConfig.EndPoint; + public string Database => this.BenchmarkConfig.Database; + public string Container => this.BenchmarkConfig.Container; public string ConsistencyLevel { get; set; } - public int Concurrency { get; set; } - public int TotalOps { get; set; } - public int? MaxRequestsPerTcpConnection { get; set; } - public int? MaxTcpConnectionsPerEndpoint { get; set; } + public int Concurrency { get; } + public int TotalOps => this.BenchmarkConfig.ItemCount; + public int? MaxRequestsPerTcpConnection => this.BenchmarkConfig.MaxRequestsPerTcpConnection; + public int? MaxTcpConnectionsPerEndpoint => this.BenchmarkConfig.MaxTcpConnectionsPerEndpoint; + [JsonProperty] public static string MachineName { get; set; } = Environment.MachineName; [JsonProperty]