From bf77518dce110274e96865934482d6bf4ab61e49 Mon Sep 17 00:00:00 2001 From: DJGosnell Date: Tue, 11 Jul 2017 12:41:36 -0400 Subject: [PATCH] Added property to return total message data size excluding headers. GUI Tests will now report the total data transferred and speed of the upload and download streams. --- .../MainWindow.xaml | 11 ++- .../MainWindow.xaml.cs | 87 +++++++++++++++---- .../Tests/ConnectionPerformanceTest.cs | 4 +- .../Tests/ConnectionPerformanceTestSession.cs | 8 -- .../Tests/MqBaseTestSession.cs | 30 ++++++- .../Tests/PerformanceTest.cs | 1 + src/DtronixMessageQueue/MqMessage.cs | 5 ++ .../Socket/SocketSession.cs | 2 +- 8 files changed, 117 insertions(+), 31 deletions(-) diff --git a/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml b/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml index e0bc391..f78fc47 100644 --- a/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml +++ b/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml @@ -55,13 +55,22 @@ - + + + + + + + + + + diff --git a/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml.cs b/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml.cs index 75de0cd..891d2c0 100644 --- a/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml.cs +++ b/src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml.cs @@ -86,6 +86,34 @@ public string ClientConnections { set { SetValue(ClientConnectionsProperty, value); } } + public static readonly DependencyProperty TotalTransferredProperty = DependencyProperty.Register( + "TotalTransferred", typeof(string), typeof(MainWindow), new PropertyMetadata(default(string))); + + public string TotalTransferred + { + get { return (string) GetValue(TotalTransferredProperty); } + set { SetValue(TotalTransferredProperty, value); } + } + + + public static readonly DependencyProperty TransferDownProperty = DependencyProperty.Register( + "TransferDown", typeof(string), typeof(MainWindow), new PropertyMetadata(default(string))); + + public string TransferDown + { + get { return (string) GetValue(TransferDownProperty); } + set { SetValue(TransferDownProperty, value); } + } + + public static readonly DependencyProperty TransferUpProperty = DependencyProperty.Register( + "TransferUp", typeof(string), typeof(MainWindow), new PropertyMetadata(default(string))); + + public string TransferUp + { + get { return (string) GetValue(TransferUpProperty); } + set { SetValue(TransferUpProperty, value); } + } + public static readonly DependencyProperty IpAddressProperty = DependencyProperty.Register( "IpAddress", typeof(string), typeof(MainWindow), new PropertyMetadata(default(string))); @@ -99,6 +127,9 @@ public string IpAddress private Process _currentProcess; private Timer _processMemoryTimer; + private Stopwatch _totalTransferStopwatch; + private long _lastTotalSent = 0; + private long _lastTotalReceived = 0; public MainWindow(string[] args) { @@ -126,10 +157,10 @@ public MainWindow(string[] args) } _processMemoryTimer = new Timer(MemoryTimer); - _processMemoryTimer.Change(100, 1000); + _totalTransferStopwatch = Stopwatch.StartNew(); - ClientConnections = "50"; + ClientConnections = "100"; IpAddress = Dns.GetHostEntry(Dns.GetHostName()) .AddressList.First( @@ -140,26 +171,48 @@ public MainWindow(string[] args) } + private void MemoryTimer(object state) { + Dispatcher.Invoke(() => + { + using (Process currentProcess = Process.GetCurrentProcess()) + MemoryUsage = FormatSize(currentProcess.WorkingSet64); + + TotalTransferred = + FormatSize(ConnectionPerformanceTestSession.TotalReceieved + ConnectionPerformanceTestSession.TotalSent); + + TransferDown = + FormatSize((double) (ConnectionPerformanceTestSession.TotalReceieved - _lastTotalReceived) / + _totalTransferStopwatch.ElapsedMilliseconds) + "ps"; + + TransferUp = + FormatSize((double)(ConnectionPerformanceTestSession.TotalSent - _lastTotalSent) / + _totalTransferStopwatch.ElapsedMilliseconds) + "ps"; + + _lastTotalReceived = ConnectionPerformanceTestSession.TotalReceieved; + _lastTotalSent = ConnectionPerformanceTestSession.TotalSent; - using (Process currentProcess = Process.GetCurrentProcess()) + _totalTransferStopwatch.Restart(); + }); + + } + + private string FormatSize(double length) + { + double size = length; + + string[] sizes = { "B", "KB", "MB", "GB", "TB" }; + int order = 0; + while (size >= 1024 && order < sizes.Length - 1) { - double size = currentProcess.WorkingSet64; - - string[] sizes = {"B", "KB", "MB", "GB", "TB"}; - int order = 0; - while (size >= 1024 && order < sizes.Length - 1) - { - order++; - size = size / 1024; - } - - Dispatcher.Invoke(() => - { - MemoryUsage = $"{size:0.##} {sizes[order]}"; - }); + order++; + size = size / 1024; } + + + return $"{size:0.0} {sizes[order]}"; + } private void Stop(object sender, RoutedEventArgs e) diff --git a/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTest.cs b/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTest.cs index d0f7c95..6014127 100644 --- a/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTest.cs +++ b/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTest.cs @@ -62,7 +62,7 @@ public override void StartServer(int clientConnections) Ip = "0.0.0.0", Port = 2121, PingTimeout = 1000, - MaxConnections = 100 + MaxConnections = 1000 }); @@ -92,7 +92,7 @@ public override void StartServer(int clientConnections) _server.Ready += (sender, args) => { Log("Client Connected"); - args.Session.GetProxy().StartConnectionTest(clientConnections, 128, 3000); + args.Session.GetProxy().StartConnectionTest(clientConnections, 1024, 3000); }; _server.SessionSetup += OnServerSessionSetup; diff --git a/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTestSession.cs b/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTestSession.cs index c9f5cf0..4f09434 100644 --- a/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTestSession.cs +++ b/src/DtronixMessageQueue.Tests.Gui/Tests/ConnectionPerformanceTestSession.cs @@ -35,14 +35,6 @@ public override void StartTest() } } - protected override void ServerMessage(Queue messageQueue) - { - - } - - protected override void ClientMessage(Queue messageQueue) - { - } private void RandomByteMessage(object state) { diff --git a/src/DtronixMessageQueue.Tests.Gui/Tests/MqBaseTestSession.cs b/src/DtronixMessageQueue.Tests.Gui/Tests/MqBaseTestSession.cs index 4ccca60..308729a 100644 --- a/src/DtronixMessageQueue.Tests.Gui/Tests/MqBaseTestSession.cs +++ b/src/DtronixMessageQueue.Tests.Gui/Tests/MqBaseTestSession.cs @@ -8,6 +8,10 @@ namespace DtronixMessageQueue.Tests.Gui.Tests public abstract class MqBaseTestSession : MqSession where T : MqSession, new() { + + public static long TotalReceieved; + public static long TotalSent; + protected MqMessageReader Reader; protected MqMessageWriter Writer; protected readonly Stopwatch Stopwatch = new Stopwatch(); @@ -49,10 +53,32 @@ protected byte[] RandomBytes(int len) return val; } + protected override void Send(byte[] buffer, int offset, int length) + { + base.Send(buffer, offset, length); + Interlocked.Add(ref TotalSent, length); + } public abstract void StartTest(); - protected abstract void ClientMessage(Queue messageQueue); - protected abstract void ServerMessage(Queue messageQueue); + + + protected virtual void ServerMessage(Queue messageQueue) + { + for (int i = 0; i < messageQueue.Count; i++) + { + var message = messageQueue.Dequeue(); + Interlocked.Add(ref TotalReceieved, message.Size); + } + } + + protected virtual void ClientMessage(Queue messageQueue) + { + for (int i = 0; i < messageQueue.Count; i++) + { + var message = messageQueue.Dequeue(); + Interlocked.Add(ref TotalReceieved, message.Size); + } + } } } diff --git a/src/DtronixMessageQueue.Tests.Gui/Tests/PerformanceTest.cs b/src/DtronixMessageQueue.Tests.Gui/Tests/PerformanceTest.cs index 73e0422..4da178e 100644 --- a/src/DtronixMessageQueue.Tests.Gui/Tests/PerformanceTest.cs +++ b/src/DtronixMessageQueue.Tests.Gui/Tests/PerformanceTest.cs @@ -7,6 +7,7 @@ public abstract class PerformanceTest public string Name { get; } public MainWindow MainWindow { get; } + public long ServerThroughput { get; set; } protected PerformanceTest(string name, MainWindow mainWindow) { diff --git a/src/DtronixMessageQueue/MqMessage.cs b/src/DtronixMessageQueue/MqMessage.cs index 68db071..9f55b69 100644 --- a/src/DtronixMessageQueue/MqMessage.cs +++ b/src/DtronixMessageQueue/MqMessage.cs @@ -43,6 +43,11 @@ public MqFrame this[int index] /// public int Size => _frames.Sum(frame => frame.FrameSize); + /// + /// The total size of the raw frames minus the headers contained in this message. + /// + public int DataLength => _frames.Sum(frame => frame.DataLength); + public MqMessage() { } diff --git a/src/DtronixMessageQueue/Socket/SocketSession.cs b/src/DtronixMessageQueue/Socket/SocketSession.cs index 8f6c26e..01488cc 100644 --- a/src/DtronixMessageQueue/Socket/SocketSession.cs +++ b/src/DtronixMessageQueue/Socket/SocketSession.cs @@ -260,7 +260,7 @@ protected virtual void IoCompleted(object sender, SocketAsyncEventArgs e) /// Buffer bytes to send. /// Offset in the buffer. /// Total bytes to send. - protected void Send(byte[] buffer, int offset, int length) + protected virtual void Send(byte[] buffer, int offset, int length) { if (Socket == null || Socket.Connected == false) {