mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-04-29 06:48:41 +00:00
Tests
This commit is contained in:
@@ -8,24 +8,30 @@
|
||||
// Usage: dotnet run -- --host 127.0.0.1 --port 10901 --resources 10000
|
||||
// ============================================================
|
||||
|
||||
using Esiur.Protocol;
|
||||
using Esiur.Resource;
|
||||
using System.Diagnostics;
|
||||
|
||||
var host = GetArg(args, "--host", "127.0.0.1");
|
||||
var port = int.Parse(GetArg(args, "--port", "10901"));
|
||||
var host = GetArg(args, "--host", "127.0.0.1");
|
||||
var port = int.Parse(GetArg(args, "--port", "10901"));
|
||||
var resourceCount = int.Parse(GetArg(args, "--resources", "10000"));
|
||||
var batchSize = int.Parse(GetArg(args, "--batch", "100"));
|
||||
var batchSize = int.Parse(GetArg(args, "--batch", "100"));
|
||||
|
||||
Console.WriteLine($"[Client-T2] Connecting to {host}:{port}, resources={resourceCount}");
|
||||
|
||||
var wh = new Warehouse();
|
||||
|
||||
var connnection = await wh.Get<EpConnection>(
|
||||
$"ep://{host}:{port}");
|
||||
|
||||
var attachLatencies = new List<double>(resourceCount);
|
||||
var proxies = new dynamic[resourceCount];
|
||||
var proxies = new IResource[resourceCount];
|
||||
|
||||
// --- Attach in batches to avoid overwhelming the runtime -------------
|
||||
var totalSw = Stopwatch.StartNew();
|
||||
var wh = new Warehouse();
|
||||
for (int batch = 0; batch < resourceCount; batch += batchSize)
|
||||
{
|
||||
|
||||
int end = Math.Min(batch + batchSize, resourceCount);
|
||||
var batchTasks = new Task[end - batch];
|
||||
|
||||
@@ -35,8 +41,8 @@ for (int batch = 0; batch < resourceCount; batch += batchSize)
|
||||
batchTasks[i - batch] = Task.Run(async () =>
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
proxies[capturedI] = await wh.Get<IResource>(
|
||||
$"iip://{host}:{port}/sys/sensor_{capturedI}");
|
||||
proxies[capturedI] = await connnection.Get($"sys/sensor_{capturedI}");
|
||||
|
||||
sw.Stop();
|
||||
|
||||
lock (attachLatencies)
|
||||
@@ -45,7 +51,7 @@ for (int batch = 0; batch < resourceCount; batch += batchSize)
|
||||
}
|
||||
|
||||
await Task.WhenAll(batchTasks);
|
||||
|
||||
//Console.WriteLine("D");
|
||||
if (batch % 1000 == 0)
|
||||
Console.WriteLine($"[Client-T2] Attached {Math.Min(batch + batchSize, resourceCount)}/{resourceCount} " +
|
||||
$"elapsed={totalSw.Elapsed.TotalSeconds:F1}s");
|
||||
@@ -60,10 +66,10 @@ int n = attachLatencies.Count;
|
||||
|
||||
Console.WriteLine($"[Client-T2] Attach latency (ms):");
|
||||
Console.WriteLine($" min={attachLatencies[0]:F2}");
|
||||
Console.WriteLine($" p50={attachLatencies[(int)(n*0.50)]:F2}");
|
||||
Console.WriteLine($" p95={attachLatencies[(int)(n*0.95)]:F2}");
|
||||
Console.WriteLine($" p99={attachLatencies[(int)(n*0.99)]:F2}");
|
||||
Console.WriteLine($" max={attachLatencies[n-1]:F2}");
|
||||
Console.WriteLine($" p50={attachLatencies[(int)(n * 0.50)]:F2}");
|
||||
Console.WriteLine($" p95={attachLatencies[(int)(n * 0.95)]:F2}");
|
||||
Console.WriteLine($" p99={attachLatencies[(int)(n * 0.99)]:F2}");
|
||||
Console.WriteLine($" max={attachLatencies[n - 1]:F2}");
|
||||
Console.WriteLine($" mean={attachLatencies.Average():F2}");
|
||||
|
||||
// --- Notification round-trip after full load ------------------------
|
||||
@@ -74,13 +80,15 @@ double sumLatencyMs = 0;
|
||||
for (int i = 0; i < Math.Min(500, resourceCount); i++)
|
||||
{
|
||||
int capturedI = i;
|
||||
proxies[capturedI].OnPropertyModified += (string propName, object oldVal, object newVal) =>
|
||||
proxies[capturedI].Instance.PropertyModified += (PropertyModificationInfo data) =>
|
||||
{
|
||||
if (propName == "Value")
|
||||
if (data.Name == "Value")
|
||||
Interlocked.Increment(ref received);
|
||||
};
|
||||
}
|
||||
|
||||
await connnection.Call("UpdateValues");
|
||||
|
||||
await Task.Delay(10000); // observe for 10s
|
||||
Console.WriteLine($"[Client-T2] Received {received} notifications in 10s from first 500 resources");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user