private async Task WriteDto(int taskId, PerfTestDto testObj) { for (var cnt = 0; cnt < Config.Records; cnt++) { await _dbClient.AddDocumentInCollection(testObj); this.RequestUnitsConsumed[taskId] += WRITE_RU; Interlocked.Increment(ref this._itemsInserted); } Interlocked.Decrement(ref this._pendingTaskCount); }
public async Task Run() { Logger.Info($"Starting a load run with a concurrency of {Config.Concurrency} and number of records: {Config.Records}"); this.RequestUnitsConsumed = new double[Config.Concurrency]; // Task based execution for (var thrd = 0; thrd < Config.Concurrency; thrd++) { this.RequestUnitsConsumed[thrd] = 0; var storeNumber = System.Threading.Thread.CurrentThread.ManagedThreadId; var testObj = new PerfTestDto { StoreNumber = storeNumber, Key = thrd.ToString(), Value = RandomString(1023768) }; this._fileSize = Size(testObj); this._fileSizeString = SizeString(testObj); if (this._fileSize > 90000 && this._fileSize < 110000) { READ_RU = READ_RU * 10; WRITE_RU = WRITE_RU * 10; } if (Config.ReadWrite == "W") { _tasks.Add(WriteDto(thrd, testObj)); } else { _tasks.Add(ReadDto(thrd)); } } _tasks.Add(LogOutputStats()); await Task.WhenAll(_tasks); // run // clean up if (Config.CleanupOnFinish) { this.Cleanup(); } }