int ReadLogicalLog( ILogicalLog logicalLog, byte[] buffer, int readOffset, int bufferOffset, int count) { if (readOffset != -1) { logicalLog.SeekForRead(readOffset, SeekOrigin.Begin); } Task <int> t = logicalLog.ReadAsync(buffer, bufferOffset, count, 0, CancellationToken.None); t.Wait(); return(t.Result); }
private async Task LogPerformanceWorkloadWorker( ILogicalLog lLog, int readRecordSize, CancellationToken CancelToken ) { int totalWriteBytes = numberWriteRecords * writeRecordSize; byte[] readRecord = new byte[readRecordSize]; // // Compute old way // Stopwatch sw = new Stopwatch(); int numberReadRecords = (totalWriteBytes / readRecordSize) + 1; lLog.SeekForRead(0, System.IO.SeekOrigin.Begin); int writtenRecordIndex = 0; int writtenRecordOffset = 0; long time; // Reenable this only to test old style performance #if false sw.Start(); for (int i = 0; i < numberReadRecords; i++) { int bytesRead; bytesRead = await lLog.ReadAsync(readRecord, 0, readRecordSize, 0, CancellationToken.None); for (int j = 0; j < bytesRead; j++) { if (readRecord[j] != (byte)(writtenRecordOffset * writtenRecordIndex)) { Console.WriteLine("Old Failed validation {0} {1}", writtenRecordIndex, writtenRecordOffset); throw new InvalidDataException(); } writtenRecordOffset++; if (writtenRecordOffset == writeRecordSize) { writtenRecordIndex++; writtenRecordOffset = 0; } } } sw.Stop(); time = sw.ElapsedMilliseconds; Interlocked.Add(ref this.TotalByteCount, totalWriteBytes); Interlocked.Add(ref this.TotalElapsedMs, time); Console.WriteLine("Read with small records {0} ms", time); #endif // Compute New Way writtenRecordIndex = 0; writtenRecordOffset = 0; sw = new Stopwatch(); lLog.SeekForRead(0, System.IO.SeekOrigin.Begin); sw.Start(); for (int i = 0; i < numberReadRecords; i++) { int bytesRead; bytesRead = await lLog.ReadAsync(readRecord, 0, readRecordSize, readRecordSize, CancellationToken.None); for (int j = 0; j < bytesRead; j++) { if (readRecord[j] != (byte)(writtenRecordOffset * writtenRecordIndex)) { Console.WriteLine("New Failed validation {0} {1}", writtenRecordIndex, writtenRecordOffset); throw new InvalidDataException(); } writtenRecordOffset++; if (writtenRecordOffset == writeRecordSize) { writtenRecordIndex++; writtenRecordOffset = 0; } } } sw.Stop(); time = sw.ElapsedMilliseconds; Console.WriteLine("Read with large records {0} ms", time); Interlocked.Add(ref this.TotalElapsedMsLargeReads, time); return; }