private Task<BenchmarkResult> DoWrite(BenchmarkParameters parameters, bool seq) { var random = new Random(); var generator = new RandomGenerator(); var result = new BenchmarkResult(parameters); var tasks = new List<Task>(parameters.Num); long bytes = 0; for (var i = 0; i < parameters.Num; i += parameters.EntriesPerBatch) { var batch = new WriteBatch(); for (var j = 0; j < parameters.EntriesPerBatch; j++) { var k = seq ? i + j : random.Next() % options.Num; var key = string.Format("{0:0000000000000000}", k); batch.Put(key, generator.Generate(parameters.ValueSize)); bytes += parameters.ValueSize + key.Length; result.FinishOperation(); } tasks.Add(storage.Writer.WriteAsync(batch, new WriteOptions { FlushToDisk = parameters.Sync })); } result.AddBytes(bytes); return Task.WhenAll(tasks).ContinueWith(t => result); }
private async Task ProcessWrites(int size, int timeToWait) { var generator = new RandomGenerator(); var random = new Random(); while (true) { try { var batchSize = random.Next(1, 10); var batch = new WriteBatch(); for (var i = 0; i < batchSize; i++) { var k = random.Next(); var key = string.Format("{0:0000000000000000}", k); batch.Put(key, generator.Generate(size)); } await storage.Writer.WriteAsync(batch); statistics.NumberOfWrites += batchSize; statistics.NumberOfWritesSinceLastReport += batchSize; statistics.BytesWritten += batchSize * (size + 16); await Task.Delay(timeToWait); } catch (Exception) { statistics.NumberOfWriteExceptions++; } } }
private Task<BenchmarkResult> ReadWhileWriting(BenchmarkParameters parameters) { var random = new Random(); var generator = new RandomGenerator(); var readTask = ReadRandom(parameters); Task.Factory.StartNew(async () => { while (readTask.IsCompleted == false) { var batch = new WriteBatch(); var k = random.Next() % options.Num; var key = string.Format("{0:0000000000000000}", k); batch.Put(key, generator.Generate(parameters.ValueSize)); await storage.Writer.WriteAsync(batch); } }); return readTask; }
private async Task DoWrite(Storage storage, int num, bool seq) { var random = new Random(); var generator = new RandomGenerator(); for (var i = 0; i < num; i += 1) { var batch = new WriteBatch(); for (var j = 0; j < 1; j++) { var k = seq ? i + j : random.Next() % num; var key = string.Format("{0:0000000000000000}", k); batch.Put(key, generator.Generate(100)); } await storage.Writer.WriteAsync(batch); } }