private async Task ReadLogFileBypassStream( ILogicalLog lLog, int readRecordSize ) { long totalWriteBytes = lLog.Length; byte[] readRecord = new byte[readRecordSize]; long ticksWaiting = 0; long ticksReading = 0; long frequencyPerMs = Stopwatch.Frequency / 1000; Stopwatch swTotal = new Stopwatch(); Stopwatch swWaiting = new Stopwatch(); Stopwatch swReading = new Stopwatch(); long totalReadBytes = 0; swTotal.Start(); while (totalReadBytes < totalWriteBytes) { long bytesRead; swReading.Restart(); bytesRead = await lLog.ReadAsync(readRecord, 0, readRecord.Length, readRecord.Length, CancellationToken.None); swReading.Stop(); totalReadBytes += bytesRead; ticksReading += swReading.ElapsedTicks; #if INCLUDE_WAITING_TIME swWaiting.Restart(); int waitingms = rnd.Next(15); if (waitingms == 3) { waitingms = 1; } else { waitingms = 0; } await Task.Delay(waitingms); swWaiting.Stop(); ticksWaiting += swWaiting.ElapsedTicks; #endif } swTotal.Stop(); Console.WriteLine("Bypass Stream: Size {0} Bytes Read {1} Elapsed ms {2} Waiting ms {3} Reading ms {4}", readRecord.Length, totalReadBytes, swTotal.ElapsedMilliseconds, ticksWaiting / frequencyPerMs, ticksReading / frequencyPerMs); return; }
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; }