This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started simplification of tests to work across processes/terminals.
- Loading branch information
Showing
5 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/DtronixMessageQueue.Tests.Performance/ServerMqPerformanceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DtronixMessageQueue.Tests.Performance | ||
{ | ||
public class ServerMqPerformanceTests | ||
{ | ||
private MqServer<SimpleMqSession, MqConfig> _server; | ||
|
||
public ServerMqPerformanceTests(string[] args) | ||
{ | ||
_server = new MqServer<SimpleMqSession, MqConfig>(new MqConfig | ||
{ | ||
Ip = "127.0.0.1", | ||
Port = 2828 | ||
}); | ||
|
||
_server.SessionSetup += (sender, eventArgs) => | ||
{ | ||
eventArgs.Session.IsServer = true; | ||
}; | ||
|
||
|
||
} | ||
|
||
public void Start() | ||
{ | ||
_server.Start(); | ||
} | ||
} | ||
} |
127 changes: 126 additions & 1 deletion
127
src/DtronixMessageQueue.Tests.Performance/SimpleMqSession.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,131 @@ | ||
namespace DtronixMessageQueue.Tests.Performance | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Threading; | ||
using DtronixMessageQueue.Socket; | ||
|
||
namespace DtronixMessageQueue.Tests.Performance | ||
{ | ||
public class SimpleMqSession : MqSession<SimpleMqSession, MqConfig> | ||
{ | ||
private MqMessageReader reader; | ||
private MqMessageWriter writer; | ||
|
||
public bool IsServer { get; set; } | ||
|
||
public TestMode Mode { get; set; } | ||
|
||
private Stopwatch stopwatch = new Stopwatch(); | ||
|
||
private Timer _responseTimer; | ||
private int _totalThroughBytes; | ||
private int _totalThroughFrames; | ||
private int _totalThroughMessages; | ||
|
||
protected override void OnSetup() | ||
{ | ||
base.OnSetup(); | ||
|
||
reader = new MqMessageReader(); | ||
writer = new MqMessageWriter(Config); | ||
} | ||
|
||
protected override void OnIncomingMessage(object sender, IncomingMessageEventArgs<SimpleMqSession, MqConfig> e) | ||
{ | ||
if (IsServer) | ||
{ | ||
ServerMessage(e.Messages); | ||
} | ||
else | ||
{ | ||
ClientMessage(e.Messages); | ||
} | ||
} | ||
|
||
private void ClientMessage(Queue<MqMessage> message_queue) | ||
{ | ||
|
||
} | ||
|
||
public override void Close(SocketCloseReason reason) | ||
{ | ||
if (_responseTimer != null) | ||
{ | ||
_responseTimer.Change(-1, -1); | ||
_responseTimer.Dispose(); | ||
} | ||
base.Close(reason); | ||
|
||
} | ||
|
||
private void ServerMessage(Queue<MqMessage> message_queue) | ||
{ | ||
|
||
if (Mode == TestMode.Unset) | ||
{ | ||
reader.Message = message_queue.Dequeue(); | ||
|
||
Mode = (TestMode)reader.ReadByte(); // Mode | ||
|
||
if (Mode == TestMode.Throughput) | ||
{ | ||
_responseTimer = new Timer(ThroughputResponse); | ||
writer.Write((byte)ServerMessageType.Ready); | ||
Send(writer.ToMessage(true)); | ||
|
||
_responseTimer.Change(1000, 1000); | ||
} | ||
|
||
} | ||
|
||
while (message_queue.Count > 0) | ||
{ | ||
var message = message_queue.Dequeue(); | ||
if (Mode == TestMode.Throughput) | ||
{ | ||
Interlocked.Add(ref _totalThroughBytes, message.Size); | ||
_totalThroughMessages++; | ||
Interlocked.Add(ref _totalThroughFrames, message.Count); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
private void ThroughputResponse(object state) | ||
{ | ||
using (var writer = new MqMessageWriter(Config)) | ||
{ | ||
var throughBytes = _totalThroughBytes; | ||
var throughMessages = _totalThroughMessages; | ||
var throughFrames = _totalThroughFrames; | ||
|
||
_totalThroughBytes = 0; | ||
_totalThroughMessages = 0; | ||
_totalThroughFrames = 0; | ||
|
||
writer.Write((byte)ServerMessageType.ThroughputTransfer); | ||
writer.Write(throughBytes); | ||
writer.Write(throughMessages); | ||
writer.Write(throughFrames); | ||
writer.Write(stopwatch.ElapsedMilliseconds); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
public enum TestMode | ||
{ | ||
Unset = 0, | ||
Throughput = 1, | ||
Repeat = 2 | ||
} | ||
|
||
public enum ServerMessageType : byte | ||
{ | ||
Unset = 0, | ||
Ready = 1, | ||
Complete = 2, | ||
ThroughputTransfer = 3 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/DtronixMessageQueue.Tests.Performance/TestStartArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DtronixMessageQueue.Tests.Performance | ||
{ | ||
public class TestStartArgs | ||
{ | ||
public StartMode Mode { get; set; } | ||
|
||
|
||
|
||
public enum StartMode | ||
{ | ||
ServerRepeat, | ||
ServerRespond, | ||
Client | ||
} | ||
} | ||
} |