Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Added property to return total message data size excluding headers.
Browse files Browse the repository at this point in the history
GUI Tests will now report the total data transferred and speed of the upload and download streams.
  • Loading branch information
DJGosnell committed Jul 11, 2017
1 parent 81a3bba commit bf77518
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 31 deletions.
11 changes: 10 additions & 1 deletion src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,22 @@
<Button Padding="4" Margin="5,0" VerticalAlignment="Center" Click="NewClient" IsEnabled="{Binding IsServer}">New Client</Button>
</StackPanel>
<StatusBar Grid.Row="4">
<TextBlock Text="{Binding Path=CurrentStatus, FallbackValue=Idle}" Width="100" />
<TextBlock Text="{Binding Path=CurrentStatus, FallbackValue=Idle}" Width="80" />
<TextBlock Text="{Binding Path=CurrentMode, FallbackValue=Setup}" Width="50" />

<TextBlock Width="120">
<TextBlock Text="Memory: " />
<TextBlock Text="{Binding Path=MemoryUsage, FallbackValue=0.0 MB}" />
</TextBlock>

<TextBlock>
<TextBlock Text="Transfer:" />
<TextBlock Text="{Binding Path=TotalTransferred, FallbackValue=N/A}" />
<TextBlock Text="; U:" />
<TextBlock Text="{Binding Path=TransferUp, FallbackValue=N/A}" />
<TextBlock Text="; D:" />
<TextBlock Text="{Binding Path=TransferDown, FallbackValue=N/A}" />
</TextBlock>
</StatusBar>
</Grid>
</Window>
87 changes: 70 additions & 17 deletions src/DtronixMessageQueue.Tests.Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand All @@ -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)
{
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override void StartServer(int clientConnections)
Ip = "0.0.0.0",
Port = 2121,
PingTimeout = 1000,
MaxConnections = 100
MaxConnections = 1000

});

Expand Down Expand Up @@ -92,7 +92,7 @@ public override void StartServer(int clientConnections)
_server.Ready += (sender, args) =>
{
Log("Client Connected");
args.Session.GetProxy<IControllerService>().StartConnectionTest(clientConnections, 128, 3000);
args.Session.GetProxy<IControllerService>().StartConnectionTest(clientConnections, 1024, 3000);
};

_server.SessionSetup += OnServerSessionSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ public override void StartTest()
}
}

protected override void ServerMessage(Queue<MqMessage> messageQueue)
{

}

protected override void ClientMessage(Queue<MqMessage> messageQueue)
{
}

private void RandomByteMessage(object state)
{
Expand Down
30 changes: 28 additions & 2 deletions src/DtronixMessageQueue.Tests.Gui/Tests/MqBaseTestSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace DtronixMessageQueue.Tests.Gui.Tests
public abstract class MqBaseTestSession<T> : MqSession<T, MqConfig>
where T : MqSession<T, MqConfig>, new()
{

public static long TotalReceieved;
public static long TotalSent;

protected MqMessageReader Reader;
protected MqMessageWriter Writer;
protected readonly Stopwatch Stopwatch = new Stopwatch();
Expand Down Expand Up @@ -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<MqMessage> messageQueue);
protected abstract void ServerMessage(Queue<MqMessage> messageQueue);


protected virtual void ServerMessage(Queue<MqMessage> messageQueue)
{
for (int i = 0; i < messageQueue.Count; i++)
{
var message = messageQueue.Dequeue();
Interlocked.Add(ref TotalReceieved, message.Size);
}
}

protected virtual void ClientMessage(Queue<MqMessage> messageQueue)
{
for (int i = 0; i < messageQueue.Count; i++)
{
var message = messageQueue.Dequeue();
Interlocked.Add(ref TotalReceieved, message.Size);
}
}
}
}
1 change: 1 addition & 0 deletions src/DtronixMessageQueue.Tests.Gui/Tests/PerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/DtronixMessageQueue/MqMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public MqFrame this[int index]
/// </summary>
public int Size => _frames.Sum(frame => frame.FrameSize);

/// <summary>
/// The total size of the raw frames minus the headers contained in this message.
/// </summary>
public int DataLength => _frames.Sum(frame => frame.DataLength);

public MqMessage()
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/DtronixMessageQueue/Socket/SocketSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected virtual void IoCompleted(object sender, SocketAsyncEventArgs e)
/// <param name="buffer">Buffer bytes to send.</param>
/// <param name="offset">Offset in the buffer.</param>
/// <param name="length">Total bytes to send.</param>
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)
{
Expand Down

0 comments on commit bf77518

Please sign in to comment.