Files
opengenesislinkserver/tools/ci/NexNodeRegistryRegression/Program.cs
T
OpenGenesis (MPL 2.0) 73cf90eb30 feat(perf): OGLPerformance 1.2 advanced ROBUST node diagnostics (#424)
* feat(perf): bounded Linux host per-core CPU measurement in opt-in sampler

* feat(perf): shared read-only asset cache metrics interface

* feat(perf): read-only Flotsam cache hit, LRU, writer and byte-budget snapshot

* feat(perf): attach read-only asset cache diagnostics to signed heartbeat

* feat(perf): bounded per-region and Linux host-core telemetry projection

* feat(perf): read-only API projection of regional frame and host core diagnostics

* feat(perf): ROBUST diagnostic panel, curves, core meters, region and asset cache views

* feat(perf): browser-session trend charts, Linux core meters, per-region frame table and Flotsam analytics

* fix(perf): keep missing heap and allocation telemetry as gaps, not zero

* test(perf): Linux host CPU parser and bounded per-core sampling

* test(perf): node registry parses bounded signed host, region and asset samples

* feat(perf): bound telemetry to 64 regions so 42-region nodes are fully represented

* feat(perf): bound telemetry to 64 regions so 42-region nodes are fully represented

* feat(perf): bound telemetry to 64 regions so 42-region nodes are fully represented

* test(perf): read-only Flotsam cache diagnostic interface

* docs(perf): operator guide for bounded CPU/core, region, GC and asset diagnostics

* test(perf): retain all 42 regions with expanded bounded heartbeat cap

* feat(perf): reboot-aware browser trends and Flotsam cache hit ratios

* fix(perf): account for host cores omitted and document 64-region telemetry cap

* fix(perf): account for host cores omitted and document 64-region telemetry cap
2026-11-10 21:30:13 +01:00

300 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using NexVerse.Core.ControlPlane;
using NexVerse.Core.Messaging;
internal static class Program
{
private static void Require(bool condition, string message)
{
if (!condition)
throw new InvalidOperationException(message);
}
private static NexEvent Event(
string name,
Dictionary<string, string> data)
{
return new NexEvent(
name,
"nexverse.simulator",
data,
"node-regression");
}
private static int Main()
{
InMemoryNexEventBus bus = new InMemoryNexEventBus();
using NexNodeRegistry registry =
new NexNodeRegistry(bus, 90);
bus.Publish(Event(
"node.online",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["hostname"] = "sim-a.internal",
["server_version"] = "NexVerse 0.9.3.3 Dev",
["uptime_seconds"] = "120",
["process_id"] = "4242",
["working_set_bytes"] = "1048576",
["cpu_seconds"] = "3.500",
["perf_processor_count"] = "8",
["perf_process_cpu_percent"] = "53.25",
["perf_process_private_bytes"] = "3145728",
["perf_managed_heap_bytes"] = "1048576",
["perf_gc_pause_percent"] = "2.50",
["perf_threadpool_pending_items"] = "7",
["perf_host_cpu_cores_json"] =
"[{\"core_id\":0,\"usage_percent\":98.25},{\"core_id\":1,\"usage_percent\":15.5}]",
["perf_region_heartbeats_json"] =
"[{\"region_id\":\"11111111-1111-1111-1111-111111111111\",\"heartbeat_hz\":11.0," +
"\"target_hz\":11.0,\"window_frames\":100,\"work_p95_ms\":8,\"frame_p95_ms\":12," +
"\"frame_p99_ms\":28,\"work_over_budget_percent\":5.0,\"frame_over_budget_percent\":8.0}]",
["perf_asset_requests"] = "200",
["perf_asset_memory_hits"] = "100",
["perf_asset_disk_hits"] = "60",
["perf_asset_ram_bytes"] = "1048576",
["perf_asset_writer_pending_jobs"] = "2",
["region_count"] = "2",
["agent_count"] = "7",
["npc_count"] = "2",
["managed_region_commands"] = "true",
["cross_region_object_messaging"] = "true",
["cross_owner_object_messaging"] = "false",
["object_messages_per_second"] = "20",
["object_message_max_age_seconds"] = "30",
["luna_texture_diagnostic_count"] = "3",
["luna_texture_occurrence_count"] = "8",
["luna_texture_regions_affected"] = "2",
["luna_texture_last_seen_utc"] = "2026-10-05T18:00:00.0000000Z",
["luna_texture_classifications_json"] = "{\"missing\":5,\"png\":3}",
["regions"] =
"11111111-1111-1111-1111-111111111111|Alpha;" +
"22222222-2222-2222-2222-222222222222|Beta"
}));
NexNodeSnapshot first =
registry.Get("sim-a");
Require(first != null, "node.online did not create registry entry");
Require(first.State == "online", "new node must be online");
Require(first.Hostname == "sim-a.internal", "hostname mismatch");
Require(first.RegionCount == 2, "heartbeat region count mismatch");
Require(first.AgentCount == 7, "heartbeat agent count mismatch");
Require(first.NpcCount == 2, "NPCs must be included in root avatar count");
Require(first.ManagedRegionCommands,
"managed-region capability mismatch");
Require(first.CrossRegionObjectMessaging,
"cross-region object messaging capability mismatch");
Require(!first.CrossOwnerObjectMessaging,
"cross-owner object messaging capability mismatch");
Require(first.ObjectMessagesPerSecond == 20,
"object message rate projection mismatch");
Require(first.ObjectMessageMaxAgeSeconds == 30,
"object message max-age projection mismatch");
Require(first.LunaTextureDiagnosticCount == 3,
"LunaTexture diagnostic count mismatch");
Require(first.LunaTextureOccurrenceCount == 8,
"LunaTexture occurrence count mismatch");
Require(first.LunaTextureRegionsAffected == 2,
"LunaTexture affected-region count mismatch");
Require(first.LunaTextureLastSeen.HasValue,
"LunaTexture last-seen timestamp missing");
Require(first.LunaTextureClassifications["missing"] == 5 &&
first.LunaTextureClassifications["png"] == 3,
"LunaTexture classification projection mismatch");
Require(first.Regions.Count == 2, "heartbeat region list mismatch");
Require(first.HostCpuCores.Count == 2 &&
first.HostCpuCores[0].CoreId == 0 &&
first.HostCpuCores[0].UsagePercent == 98.25,
"host CPU cores must be parsed and ordered");
Require(first.RegionPerformance.Count == 1 &&
first.RegionPerformance[0].RegionId ==
"11111111-1111-1111-1111-111111111111" &&
first.RegionPerformance[0].FrameP99Ms == 28 &&
first.RegionPerformance[0].WorkOverBudgetPercent == 5,
"signed region frame timing projection mismatch");
Require(first.PerformanceMetrics["perf_asset_requests"] == 200 &&
first.PerformanceMetrics["perf_asset_ram_bytes"] == 1048576 &&
first.PerformanceMetrics["perf_asset_writer_pending_jobs"] == 2,
"signed Flotsam cache projection mismatch");
Require(first.PerformanceMetrics["perf_processor_count"] == 8 &&
first.PerformanceMetrics["perf_process_cpu_percent"] == 53.25 &&
first.PerformanceMetrics["perf_managed_heap_bytes"] == 1048576 &&
first.PerformanceMetrics["perf_gc_pause_percent"] == 2.50 &&
first.PerformanceMetrics["perf_threadpool_pending_items"] == 7,
"signed process performance projection mismatch");
// Non-finite, negative and out-of-range values must never reach World API.
bus.Publish(Event("node.heartbeat", new Dictionary<string, string>
{
["node_id"] = "sim-a",
["perf_processor_count"] = "16",
["perf_process_cpu_percent"] = "NaN",
["perf_managed_heap_bytes"] = "-1",
["perf_gc_pause_percent"] = "101",
["perf_threadpool_pending_items"] = "1e999",
["perf_arbitrary_metric"] = "12345"
}));
NexNodeSnapshot sanitized = registry.Get("sim-a");
Require(sanitized.PerformanceMetrics.Count == 1 &&
sanitized.PerformanceMetrics["perf_processor_count"] == 16,
"metrics must be finite, bounded and allowlisted");
Require(sanitized.RegionPerformance.Count == 0 &&
sanitized.HostCpuCores.Count == 0,
"missing host/region telemetry must clear previous samples");
bus.Publish(Event("node.heartbeat", new Dictionary<string, string>
{
["node_id"] = "sim-a",
["perf_host_cpu_cores_json"] =
"[{\"core_id\":0,\"usage_percent\":150.0}]",
["perf_region_heartbeats_json"] =
"[{\"region_id\":\"00000000-0000-0000-0000-000000000000\",\"heartbeat_hz\":2," +
"\"target_hz\":2,\"window_frames\":1,\"work_p95_ms\":0,\"frame_p95_ms\":0," +
"\"frame_p99_ms\":0,\"work_over_budget_percent\":0,\"frame_over_budget_percent\":0}]"
}));
Require(registry.Get("sim-a").HostCpuCores.Count == 0 &&
registry.Get("sim-a").RegionPerformance.Count == 0,
"invalid host load and unknown regions must be rejected");
bus.Publish(Event(
"region.online",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["region_id"] = "11111111-1111-1111-1111-111111111111",
["region_name"] = "Alpha",
["server_uri"] = "http://sim-a.internal:9000/",
["size_x"] = "512",
["size_y"] = "256",
["agent_count"] = "4",
["npc_count"] = "1"
}));
NexNodeSnapshot owner =
registry.FindNodeForRegion(
"11111111-1111-1111-1111-111111111111");
Require(owner != null && owner.NodeId == "sim-a",
"region ownership lookup failed");
NexNodeRegionSnapshot alpha =
owner.Regions.First(x =>
x.RegionId ==
"11111111-1111-1111-1111-111111111111");
Require(alpha.SizeX == 512 && alpha.SizeY == 256,
"region.online size metadata mismatch");
Require(alpha.AgentCount == 4,
"region.online agent metadata mismatch");
Require(alpha.NpcCount == 1,
"region.online NPC metadata mismatch");
bus.Publish(Event("region.presence", new Dictionary<string, string>
{
["node_id"] = "sim-a",
["region_id"] = "11111111-1111-1111-1111-111111111111",
["agent_count"] = "5",
["npc_count"] = "3"
}));
NexNodeRegionSnapshot live = registry.Get("sim-a").Regions.First(
x => x.RegionId == "11111111-1111-1111-1111-111111111111");
Require(live.AgentCount == 5 && live.NpcCount == 3,
"periodic region.presence must include and refresh NPCs");
bus.Publish(Event(
"node.heartbeat",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["region_count"] = "1",
["agent_count"] = "4",
["npc_count"] = "1",
["luna_texture_diagnostic_count"] = "0",
["luna_texture_occurrence_count"] = "0",
["luna_texture_regions_affected"] = "0",
["luna_texture_last_seen_utc"] = "",
["luna_texture_classifications_json"] = "{}",
["perf_process_cpu_percent"] = "7.25",
["perf_managed_heap_bytes"] = "2097152",
["regions"] =
"11111111-1111-1111-1111-111111111111|Alpha"
}));
NexNodeSnapshot pruned =
registry.Get("sim-a");
Require(pruned.Regions.Count == 1,
"heartbeat must prune regions no longer reported");
Require(pruned.PerformanceMetrics["perf_process_cpu_percent"] == 7.25 &&
pruned.PerformanceMetrics["perf_managed_heap_bytes"] == 2097152,
"performance telemetry must refresh on a later heartbeat");
Require(pruned.NpcCount == 1,
"heartbeat must refresh NPC count without counting twice");
Require(pruned.LunaTextureDiagnosticCount == 0 &&
pruned.LunaTextureOccurrenceCount == 0 &&
pruned.LunaTextureRegionsAffected == 0 &&
!pruned.LunaTextureLastSeen.HasValue &&
pruned.LunaTextureClassifications.Count == 0,
"heartbeat must refresh LunaTexture aggregate projection");
Require(registry.FindNodeForRegion(
"22222222-2222-2222-2222-222222222222") == null,
"removed heartbeat region must not retain node ownership");
bus.Publish(Event(
"node.offline",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["regions"] =
"11111111-1111-1111-1111-111111111111|Alpha"
}));
Require(registry.Get("sim-a").State == "offline",
"node.offline must mark node offline");
Require(registry.Get("sim-a").PerformanceMetrics.Count == 0,
"offline event must clear stale resource measurements");
bus.Publish(Event(
"node.heartbeat",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["region_count"] = "1",
["agent_count"] = "4",
["regions"] =
"11111111-1111-1111-1111-111111111111|Alpha"
}));
Require(registry.Get("sim-a").State == "online",
"heartbeat must revive an offline node");
bus.Publish(Event(
"region.offline",
new Dictionary<string, string>
{
["node_id"] = "sim-a",
["region_id"] = "11111111-1111-1111-1111-111111111111"
}));
NexNodeSnapshot empty =
registry.Get("sim-a");
Require(empty.RegionCount == 0 && empty.Regions.Count == 0,
"region.offline must remove region from node");
Require(registry.FindNodeForRegion(
"11111111-1111-1111-1111-111111111111") == null,
"offline region must no longer resolve to a node");
Require(registry.StaleAfterSeconds == 90,
"registry stale threshold mismatch");
Console.WriteLine("NexVerse NodeAgent registry regression: OK");
return 0;
}
}