private async Task LogOutputStats() { long lastCount = 0; double lastRequestUnits = 0; double lastSeconds = 0; double requestUnits = 0; double ruPerSecond = 0; double ruPerMonth = 0; Stopwatch watch = new Stopwatch(); watch.Start(); while (this.pendingTaskCount > 0) { await Task.Delay(TimeSpan.FromSeconds(1)); double seconds = watch.Elapsed.TotalSeconds; requestUnits = this.RequestUnitsConsumed.Sum(); long currentCount = this.itemsInserted; ruPerSecond = (requestUnits / seconds); ruPerMonth = ruPerSecond * 86400 * 30; Console.WriteLine("Inserted {0} docs @ {1} writes/s, {2} RU/s ({3}B max monthly 1KB reads)", currentCount, Math.Round(this.itemsInserted / seconds), Math.Round(ruPerSecond), Math.Round(ruPerMonth / (1000 * 1000 * 1000))); lastCount = itemsInserted; lastSeconds = seconds; lastRequestUnits = requestUnits; } double totalSeconds = watch.Elapsed.TotalSeconds; ruPerSecond = (requestUnits / totalSeconds); ruPerMonth = ruPerSecond * 86400 * 30; using (var ct = new ConsoleColoeContext(ConsoleColor.Green)) { Console.WriteLine(); Console.WriteLine("Summary:"); Console.WriteLine("--------------------------------------------------------------------- "); Console.WriteLine("Inserted {0} items @ {1} writes/s, {2} RU/s ({3}B max monthly 1KB reads)", lastCount, Math.Round(this.itemsInserted / watch.Elapsed.TotalSeconds), Math.Round(ruPerSecond), Math.Round(ruPerMonth / (1000 * 1000 * 1000))); Console.WriteLine("--------------------------------------------------------------------- "); } }
private static void HandleParseError(IEnumerable <Error> errors) { using (var ct = new ConsoleColoeContext(ConsoleColor.Red)) { foreach (var e in errors) { Console.WriteLine(e.ToString()); } } Environment.Exit(errors.Count()); }
/// <summary> /// Main method for the sample. /// </summary> /// <param name="args">command line arguments.</param> public static async Task Main(string[] args) { BenchmarkOptions options = null; Parser.Default.ParseArguments <BenchmarkOptions>(args) .WithParsed <BenchmarkOptions>(e => options = e) .WithNotParsed <BenchmarkOptions>(e => Program.HandleParseError(e)); ThreadPool.SetMinThreads(options.MinThreadPoolSize, options.MinThreadPoolSize); string accountKey = options.Key; options.Key = null; // Don't print using (var ct = new ConsoleColoeContext(ConsoleColor.Green)) { Console.WriteLine($"{nameof(CosmosBenchmark)} started with arguments"); Console.WriteLine("--------------------------------------------------------------------- "); Console.WriteLine(JsonConvert.SerializeObject(options, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented, })); Console.WriteLine("--------------------------------------------------------------------- "); Console.WriteLine(); } CosmosClientOptions clientOptions = new CosmosClientOptions() { ApplicationName = "cosmosdbdotnetbenchmark", RequestTimeout = new TimeSpan(1, 0, 0), MaxRetryAttemptsOnRateLimitedRequests = 10, MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds(60), }; using (var client = new CosmosClient( options.EndPoint, accountKey, clientOptions)) { var program = new Program(client); await program.RunAsync(options); Console.WriteLine("CosmosBenchmark completed successfully."); } Console.WriteLine("Press any key to exit..."); Console.ReadLine(); }