Skip to content

Commit 591ec50

Browse files
committed
Commit Stable
1 parent 8deedf7 commit 591ec50

File tree

71 files changed

+2306
-1699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2306
-1699
lines changed

Benchmarks/SslBenchmark/Program.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using System.Security.Cryptography.X509Certificates;
1515
using System.Net.Security;
1616
using NetworkLibrary.TCP;
17+
using NetworkLibrary;
18+
using NetworkLibrary.Components.Statistics;
1719

1820
namespace SslBenchmark
1921
{
@@ -27,6 +29,8 @@ static void Main(string[] args)
2729
}
2830
private static void Bench()
2931
{
32+
BufferPool.ForceGCOnCleanup = true;
33+
Random rng = new Random(42);
3034
MiniLogger.AllLog += (log) => Console.WriteLine(log);
3135
int NumFinishedClients = 0;
3236
int totMsgClient = 0;
@@ -40,18 +44,19 @@ private static void Bench()
4044
var scert = new X509Certificate2("server.pfx", "greenpass");
4145
var ccert = new X509Certificate2("client.pfx", "greenpass");
4246

43-
SslByteMessageServer server = new SslByteMessageServer(2008, clientAmount * 2, scert);
47+
SslByteMessageServer server = new SslByteMessageServer(2008, scert);
4448
List<SslByteMessageClient> clients = new List<SslByteMessageClient>();
4549

4650
Stopwatch sw2 = new Stopwatch();
4751
AutoResetEvent testCompletionEvent = new AutoResetEvent(false);
4852

4953

5054

51-
server.MaxIndexedMemoryPerClient = 1280000000;
55+
server.MaxIndexedMemoryPerClient = 128000000;
5256
server.DropOnBackPressure = false;
5357
server.OnBytesReceived += OnServerReceviedMessage;
5458
server.RemoteCertificateValidationCallback += ValidateCertAsServer;
59+
server.GatherConfig = ScatterGatherConfig.UseQueue;
5560
Console.Read();
5661
server.StartServer();
5762
Console.Read();
@@ -60,7 +65,7 @@ private static void Bench()
6065
{
6166
var client = new SslByteMessageClient(ccert);
6267
client.RemoteCertificateValidationCallback += ValidateCertAsClient;
63-
client.BufferProvider = server.BufferProvider;
68+
client.GatherConfig= ScatterGatherConfig.UseQueue;
6469
client.OnBytesReceived += (buffer, offset, count) => OnClientReceivedMessage(client, buffer, offset, count);
6570
client.MaxIndexedMemory = server.MaxIndexedMemoryPerClient;
6671
client.Connect("127.0.0.1", 2008);
@@ -124,6 +129,8 @@ void ShowStatus()
124129
Console.WriteLine(" Request-Response Per second " + totMsgClient / elapsedSeconds);
125130
Console.WriteLine("Data transmissıon rate Inbound " + message.Length * messagePerSecond / 1000000 + " Megabytes/s");
126131
Console.WriteLine("Data transmissıon rate Outbound " + response.Length * messagePerSecond / 1000000 + " Megabytes/s");
132+
server.GetStatistics(out SessionStats general, out var _);
133+
Console.WriteLine(general.ToString());
127134
}
128135

129136
void OnClientReceivedMessage(SslByteMessageClient client, byte[] arg2, int offset, int count)

Benchmarks/SslBenchmark2/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static void CustomSslTest()
4141
var scert = new X509Certificate2("server.pfx", "greenpass");
4242
var ccert = new X509Certificate2("client.pfx", "greenpass");
4343

44-
CustomSslServer server = new CustomSslServer(2008, scert, clientAmount * 2 );
44+
CustomSslServer server = new CustomSslServer(2008, scert);
4545
List<CustomSslClient> clients = new List<CustomSslClient>();
4646

4747
Stopwatch sw2 = new Stopwatch();
@@ -58,7 +58,6 @@ private static void CustomSslTest()
5858
for (int i = 0; i < clientAmount; i++)
5959
{
6060
var client = new CustomSslClient(ccert);
61-
client.BufferManager = server.BufferManager;
6261
client.OnBytesReceived += ( byte[] arg2, int offset, int count) => OnClientReceivedMessage(client, arg2, offset, count);
6362
client.MaxIndexedMemory = server.MaxIndexedMemoryPerClient;
6463
client.ConnectAsyncAwaitable("127.0.0.1", 2008).Wait();

Benchmarks/TcpBenchmark/Program.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NetworkLibrary.TCP;
1+
using NetworkLibrary;
2+
using NetworkLibrary.Components.Statistics;
3+
using NetworkLibrary.TCP;
24
using NetworkLibrary.TCP.ByteMessage;
35
using NetworkLibrary.Utils;
46
using System;
@@ -27,6 +29,7 @@ static void Main(string[] args)
2729

2830
private static void TcpTest()
2931
{
32+
BufferPool.ForceGCOnCleanup = false;
3033
// dont change.
3134
int NumFinishedClients = 0;
3235
//CoreAssemblyConfig.UseUnmanaged=true;
@@ -41,13 +44,13 @@ private static void TcpTest()
4144
var response = new byte[32];
4245

4346

44-
ByteMessageTcpServer server = new ByteMessageTcpServer(2008, clientAmount*2);
47+
ByteMessageTcpServer server = new ByteMessageTcpServer(2008);
4548
List<ByteMessageTcpClient> clients = new List<ByteMessageTcpClient>();
4649

4750
Stopwatch sw2 = new Stopwatch();
4851
AutoResetEvent testCompletionEvent = new AutoResetEvent(false);
4952

50-
server.MaxIndexedMemoryPerClient = 1280000000;
53+
server.MaxIndexedMemoryPerClient = 12800000;
5154
server.ClientSendBufsize = 128000;
5255
server.ClientReceiveBufsize = 128000;
5356
server.DropOnBackPressure = false;
@@ -60,9 +63,8 @@ private static void TcpTest()
6063
for (int i = 0; i < clientAmount; i++)
6164
{
6265
var client = new ByteMessageTcpClient();
63-
client.BufferManager = server.BufferManager;
6466
client.MaxIndexedMemory = server.MaxIndexedMemoryPerClient;
65-
67+
client.GatherConfig = ScatterGatherConfig.UseQueue;
6668
client.DropOnCongestion = false;
6769
client.OnBytesReceived += (byte[] arg2, int offset, int count) => OnClientReceivedMessage(client, arg2, offset, count);
6870

@@ -167,6 +169,7 @@ void OnServerReceviedMessage(in Guid id, byte[] arg2, int offset, int count)
167169

168170
private static void TcpTest2()
169171
{
172+
170173
// dont change.
171174
int NumFinishedClients = 0;
172175
MiniLogger.AllLog += (string log) => Console.WriteLine(log);
@@ -180,25 +183,26 @@ private static void TcpTest2()
180183
var response = new byte[32];
181184

182185
bool done = false;
183-
int port = 20011;
184-
ByteMessageTcpServer server = new ByteMessageTcpServer(port, clientAmount * 3);
186+
int port = 20007;
187+
ByteMessageTcpServer server = new ByteMessageTcpServer(port);
185188
List<ByteMessageTcpClient> clients = new List<ByteMessageTcpClient>();
186189

187190
Stopwatch sw2 = new Stopwatch();
188191
AutoResetEvent testCompletionEvent = new AutoResetEvent(false);
189192

190-
server.MaxIndexedMemoryPerClient = 128000;
193+
server.MaxIndexedMemoryPerClient = 128000000;
191194
server.ClientSendBufsize = 128000;
192195
server.ClientReceiveBufsize = 128000;
193196
server.DropOnBackPressure = false;
194197
server.OnBytesReceived += OnServerReceviedMessage;
195198
server.StartServer();
199+
server.GatherConfig = ScatterGatherConfig.UseQueue;
196200

197201
Task[] toWait = new Task[clientAmount];
198202
for (int i = 0; i < clientAmount; i++)
199203
{
200204
var client = new ByteMessageTcpClient();
201-
client.BufferManager = server.BufferManager;
205+
client.GatherConfig = ScatterGatherConfig.UseQueue;
202206
client.MaxIndexedMemory = server.MaxIndexedMemoryPerClient;
203207

204208
client.DropOnCongestion = false;
@@ -221,21 +225,13 @@ private static void TcpTest2()
221225
for (int i = 0; i < numMsg; i++)
222226
{
223227
client.SendAsync(message);
224-
225228
}
226229

227-
});
228230

229-
Task.Run(async () =>
230-
{
231-
while (!done)
232-
{
233-
await Task.Delay(2000);
234-
//ShowStatus();
235-
}
236-
237231
});
238232

233+
234+
239235
// -------- Messages are sent by clients ------
240236

241237
Console.WriteLine("All messages are dispatched in :" + sw2.ElapsedMilliseconds +
@@ -271,8 +267,12 @@ void ShowStatus()
271267
Console.WriteLine(" Request-Response Per second " + (totMsgClient / elapsedSeconds).ToString("N1"));
272268
Console.WriteLine("Data transmissıon rate Inbound " + (message.Length * messagePerSecond / 1000000).ToString("N1") + " Megabytes/s");
273269
Console.WriteLine("Data transmissıon rate Outbound " + (response.Length * messagePerSecond / 1000000).ToString("N1") + " Megabytes/s");
270+
server.GetStatistics(out SessionStats general, out var _);
271+
Console.WriteLine(general.ToString());
274272
}
275273

274+
//--------------- Msg Handlers ---------------------
275+
276276
void OnClientReceivedMessage(ByteMessageTcpClient client, byte[] arg2, int offset, int count)
277277
{
278278
Interlocked.Increment(ref totMsgClient);

NetworkLibrary/Components/AesAlgorithm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ namespace NetworkLibrary.Components
88
{
99
public class AesAlgorithm:IDisposable
1010
{
11-
protected Aes algorithm;
12-
protected ICryptoTransform encryptor;
13-
protected ICryptoTransform decryptor;
11+
private readonly Aes algorithm;
12+
private readonly ICryptoTransform encryptor;
13+
private readonly ICryptoTransform decryptor;
1414

1515
public int EncryptorInputBlockSize { get => encryptor.InputBlockSize; }
1616
public int EncryptorOutputBlockSize { get => encryptor.OutputBlockSize; }
1717
public int DecryptorInputBlockSize { get => decryptor.InputBlockSize; }
1818
public int DecryptorOutputBlockSize { get => decryptor.OutputBlockSize; }
1919

20-
private byte[] finalBlock= new byte[0];
20+
private readonly byte[] finalBlock= new byte[0];
2121
public AesAlgorithm(byte[] Key, byte[] IV,string algorithmName = null)
2222
{
2323
if(algorithmName == null)

0 commit comments

Comments
 (0)