Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt implementation #9

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions src/Abc.Zerio.Client/Abc.Zerio.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<TieredCompilation>False</TieredCompilation>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Abc.Zerio\Abc.Zerio.csproj" />
Expand Down
54 changes: 47 additions & 7 deletions src/Abc.Zerio.Client/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Benchmark
{
public const int RIO_PORT = 48654;
public const int TCP_PORT = 48655;
public const int ALT_PORT = 48656;

private readonly int _hostCount;
private readonly int _serversPerHost;
Expand Down Expand Up @@ -408,7 +409,7 @@ public static void RunAll(string transportType, List<string> hosts, int secondsP

var code = string.IsNullOrWhiteSpace(suffix) ? "tcp" : "tcp" + "_" + suffix;
results.AddRange(RunWithClients(tcpClients, code, secondsPerTest, maxBandwidthMb, outFolder, hosts.Count, serverCount, clientsPerServer));

WriteResults(outFolder, dateString, results);
foreach (var tcpClient in tcpClients)
{
tcpClient.Dispose();
Expand Down Expand Up @@ -442,6 +443,42 @@ public static void RunAll(string transportType, List<string> hosts, int secondsP

var code = string.IsNullOrWhiteSpace(suffix) ? "rio" : "rio" + "_" + suffix;
results.AddRange(RunWithClients(rioClients, code, secondsPerTest, maxBandwidthMb, outFolder, hosts.Count, serverCount, clientsPerServer));
WriteResults(outFolder, dateString, results);
foreach (var rioClient in rioClients)
{
rioClient.Dispose();
}
}
break;

case "a":
case "alt":
{
var rioClients = new List<Alt.ZerioClient>();
foreach (var host in hosts)
{
for (int i = 0; i < serverCount * clientsPerServer; i++)
{
var portDelta = i % serverCount;
var tcpClient = new Alt.ZerioClient(new IPEndPoint(IPAddress.Parse(host), ALT_PORT + portDelta));

var connectedMre = new ManualResetEvent(false);
tcpClient.Connected += () => { connectedMre.Set(); };
tcpClient.Start($"alt_client_{i}");
if (!connectedMre.WaitOne(1000))
{
Console.WriteLine("Cannot connect");
return;
}

rioClients.Add(tcpClient);
}
}

var code = string.IsNullOrWhiteSpace(suffix) ? "alt" : "alt" + "_" + suffix;
results.AddRange(RunWithClients(rioClients, code, secondsPerTest, maxBandwidthMb, outFolder, hosts.Count, serverCount, clientsPerServer));

WriteResults(outFolder, dateString, results);

foreach (var rioClient in rioClients)
{
Expand All @@ -453,6 +490,12 @@ public static void RunAll(string transportType, List<string> hosts, int secondsP
throw new InvalidOperationException($"Unknown transport type: {transportType}");
}

Console.WriteLine("------------------------------");
Console.WriteLine("RunAll finished");
}

private static void WriteResults(string outFolder, string dateString, List<BenchmarkResult> results)
{
var fileName = $"Stats_{dateString}.csv";

using (var writer = new StreamWriter(Path.Combine(outFolder, fileName)))
Expand All @@ -466,9 +509,6 @@ public static void RunAll(string transportType, List<string> hosts, int secondsP
csvWriter.WriteRecords(results);
Console.Out.Flush();
}

Console.WriteLine("------------------------------");
Console.WriteLine("RunAll finished");
}

private static IEnumerable<BenchmarkResult> RunLoadWithClients(IEnumerable<IFeedClient> clients, string transportId, string outFolder, int hostCount)
Expand Down Expand Up @@ -551,9 +591,9 @@ private static IEnumerable<BenchmarkResult> RunWithClients(IEnumerable<IFeedClie
int serverCount,
int clientsPerServer)
{
var msgSizes = new[] { 32, 1024, 512, 128 }; // 2500, , 128, 32
var delays = new[] { 10, 20, 40, 100 }; // , 1000, 2000
var bursts = new[] { 50, 5, 2, 1 };
var msgSizes = new[] { 1024, 32, 512, 128 }; // 2500, , 128, 32
var delays = new[] { 10, 40, 100, 1000 }; // 20,10,, 2000
var bursts = new[] { 50, 5, 2, 1 }; // 50,

var transportFeedClients = clients.ToList();

Expand Down
13 changes: 8 additions & 5 deletions src/Abc.Zerio.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void Main(string[] args)
decimal bw = 100;
var runAll = false;
var transport = string.Empty;
var highPriority = false;
var highPriority = true;
var clientsPerServer = 1;
var suffix = string.Empty;
const int serverCount = 1;
Expand Down Expand Up @@ -67,11 +67,10 @@ static void Main(string[] args)
ShowHelp(p);
return;
}

if (string.IsNullOrEmpty(transport))
{
Console.WriteLine("Enter transport: t for TCP, r for RIO");
transport = Console.ReadLine();
Console.ReadLine();
}

if (hosts.Count == 0)
Expand Down Expand Up @@ -118,7 +117,11 @@ private static IFeedClient CreateClient(string hostname, string transportType)

case "r":
case "rio":
return new ZerioClient(new IPEndPoint(Dns.GetHostAddresses(hostname).First(i => i.AddressFamily == AddressFamily.InterNetwork), Benchmark.TCP_PORT));
return new ZerioClient(new IPEndPoint(Dns.GetHostAddresses(hostname).First(i => i.AddressFamily == AddressFamily.InterNetwork), Benchmark.RIO_PORT));

case "a":
case "alt":
return new Alt.ZerioClient(new IPEndPoint(Dns.GetHostAddresses(hostname).First(i => i.AddressFamily == AddressFamily.InterNetwork), Benchmark.ALT_PORT));

default:
throw new InvalidOperationException($"Unknown transport type: {transportType}");
Expand Down
1 change: 1 addition & 0 deletions src/Abc.Zerio.Server/Abc.Zerio.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<TieredCompilation>False</TieredCompilation>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Abc.Zerio\Abc.Zerio.csproj" />
Expand Down
16 changes: 10 additions & 6 deletions src/Abc.Zerio.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Program
{
public const int RIO_PORT = 48654;
public const int TCP_PORT = 48655;
public const int ALT_PORT = 48656;

private static long _messageCounter;

Expand All @@ -21,11 +22,13 @@ private static void Main()

Console.WriteLine("SERVER...");

using var rioServer = new ZerioServer(RIO_PORT);
using var tcpServer = new TcpFeedServer(TCP_PORT);
// using var rioServer = new ZerioServer(RIO_PORT);
//using var tcpServer = new TcpFeedServer(TCP_PORT);
using var altServer = new Alt.ZerioServer(ALT_PORT);

StartServer(rioServer);
StartServer(tcpServer);
// StartServer(rioServer);
//StartServer(tcpServer);
StartServer(altServer);

const bool alwaysPrintStats = false;
var cts = new CancellationTokenSource();
Expand Down Expand Up @@ -67,8 +70,9 @@ private static void Main()

cts.Cancel();
monitoringThread.Join();
rioServer.Stop();
tcpServer.Stop();
// rioServer.Stop();
//tcpServer.Stop();
altServer.Stop();
}

private static void StartServer(IFeedServer server)
Expand Down
1 change: 1 addition & 0 deletions src/Abc.Zerio.Tests/Abc.Zerio.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TieredCompilation>False</TieredCompilation>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Abc.Zerio\Abc.Zerio.csproj" />
Expand Down
Loading