2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-04-29 06:48:41 +00:00
This commit is contained in:
2026-04-05 12:35:27 +03:00
parent 44983d7784
commit c7d095ea96
17 changed files with 546 additions and 732 deletions
@@ -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");
@@ -18,18 +18,29 @@ Console.WriteLine($"[Server-T2] Creating {resourceCount} resources on port {port
var wh = new Warehouse();
await wh.Put("sys", new MemoryStore());
await wh.Put("sys/server", new EpServer() { Port = (ushort)port });
var server = await wh.Put("sys/server", new EpServer() { Port = (ushort)port });
long memBefore = GC.GetTotalMemory(forceFullCollection: true);
List<SensorResource> sensors = new List<SensorResource>();
for (int i = 0; i < resourceCount; i++)
{
var s = new SensorResource { SensorId = i, Value = i * 0.1 };
await wh.Put($"sys/sensor_{i}", s);
var sensor = await wh.Put($"sys/sensor_{i}",
new SensorResource { SensorId = i, Value = i * 0.1 });
sensors.Add(sensor);
}
await wh.Open();
server.MapCall("UpdateValues", () =>
{
foreach(var sensor in sensors)
{
sensor.Value += 0.1;
}
});
long memAfter = GC.GetTotalMemory(forceFullCollection: true);
double memMB = (memAfter - memBefore) / (1024.0 * 1024.0);