瀏覽代碼

Change type of properties in replay speed report

Mendel Monteiro-Beckerman 3 年之前
父節點
當前提交
ab3467a818
共有 2 個文件被更改,包括 31 次插入31 次删除
  1. 22 24
      src/Abc.Zebus.Persistence/MessageReplayer.cs
  2. 9 7
      src/Abc.Zebus.Persistence/Reporter/ReplaySpeedReport.cs

+ 22 - 24
src/Abc.Zebus.Persistence/MessageReplayer.cs

@@ -153,35 +153,33 @@ namespace Abc.Zebus.Persistence
 
         private int ReplayUnackedMessages(CancellationToken cancellationToken)
         {
-            using (var reader = _storage.CreateMessageReader(_peer.Id))
-            {
-                if (reader == null)
-                    return 0;
-                var totalMessageCount = 0;
+            using var reader = _storage.CreateMessageReader(_peer.Id);
+            if (reader == null)
+                return 0;
+            var totalMessageCount = 0;
 
-                foreach (var partition in reader.GetUnackedMessages().TakeWhile(m => !cancellationToken.IsCancellationRequested).Partition(_replayBatchSize, true))
+            foreach (var partition in reader.GetUnackedMessages().TakeWhile(m => !cancellationToken.IsCancellationRequested).Partition(_replayBatchSize, true))
+            {
+                var messageSentCount = 0;
+                var batchDuration = MeasureDuration();
+                var readAndSendDuration = MeasureDuration();
+                foreach (var message in partition.Select(DeserializeTransportMessage))
                 {
-                    var messageSentCount = 0;
-                    var batchDuration = MeasureDuration();
-                    var readAndSendDuration = MeasureDuration();
-                    foreach (var message in partition.Select(DeserializeTransportMessage))
-                    {
-                        _unackedIds.Add(message.Id);
-                        ReplayMessage(message);
-                        messageSentCount++;
-                    }
-
-                    totalMessageCount += messageSentCount;
-
-                    _logger.LogInformation($"Read and send for last batch of {messageSentCount} msgs for {_peer.Id} took {readAndSendDuration.Value}. ({messageSentCount / readAndSendDuration.Value.TotalSeconds} msg/s)");
-                    WaitForAcks(cancellationToken);
-                    _logger.LogInformation($"Last batch for {_peer.Id} took {batchDuration.Value} to be totally replayed ({messageSentCount / batchDuration.Value.TotalSeconds} msg/s)");
-                    _reporter.AddReplaySpeedReport(new ReplaySpeedReport(messageSentCount, readAndSendDuration.Value.TotalSeconds, batchDuration.Value.TotalSeconds));
+                    _unackedIds.Add(message.Id);
+                    ReplayMessage(message);
+                    messageSentCount++;
                 }
 
-                _logger.LogInformation($"Replay finished for peer {_peer.Id}. Disposing the reader");
-                return totalMessageCount;
+                totalMessageCount += messageSentCount;
+
+                _logger.LogInformation($"Read and send for last batch of {messageSentCount} msgs for {_peer.Id} took {readAndSendDuration.Value}. ({messageSentCount / readAndSendDuration.Value.TotalSeconds} msg/s)");
+                WaitForAcks(cancellationToken);
+                _logger.LogInformation($"Last batch for {_peer.Id} took {batchDuration.Value} to be totally replayed ({messageSentCount / batchDuration.Value.TotalSeconds} msg/s)");
+                _reporter.AddReplaySpeedReport(new ReplaySpeedReport(messageSentCount, readAndSendDuration.Value, batchDuration.Value));
             }
+
+            _logger.LogInformation($"Replay finished for peer {_peer.Id}. Disposing the reader");
+            return totalMessageCount;
         }
 
         private static TransportMessage DeserializeTransportMessage(byte[] row) => TransportMessage.Deserialize(row);

+ 9 - 7
src/Abc.Zebus.Persistence/Reporter/ReplaySpeedReport.cs

@@ -1,16 +1,18 @@
-namespace Abc.Zebus.Persistence.Reporter
+using System;
+
+namespace Abc.Zebus.Persistence.Reporter
 {
     public class ReplaySpeedReport
     {
         public int MessageCount { get; }
-        public double SendDurationInSeconds { get; }
-        public double AckDurationInSeconds { get; }
+        public TimeSpan SendDuration { get; }
+        public TimeSpan AckDuration { get; }
 
-        public ReplaySpeedReport(int messageCount, double sendDurationInSeconds, double ackDurationInSeconds)
+        public ReplaySpeedReport(int messageCount, TimeSpan sendDuration, TimeSpan ackDuration)
         {
             MessageCount = messageCount;
-            SendDurationInSeconds = sendDurationInSeconds;
-            AckDurationInSeconds = ackDurationInSeconds;
+            SendDuration = sendDuration;
+            AckDuration = ackDuration;
         }
     }
-}
+}