perf(router): replace 100ms Valkey polling with Pub/Sub notification wakeup and increase heartbeat to 45s
The Valkey transport layer used 100ms busy-polling loops (Task.Delay(100)) across ~90 concurrent loops in 45+ services, generating ~900 idle commands/sec and burning ~58% CPU while the system was completely idle. Replace polling with Redis Pub/Sub notifications: - Publishers fire PUBLISH after each XADD (fire-and-forget) - Consumers SUBSCRIBE and wait on SemaphoreSlim with 30s fallback timeout - Applies to both ValkeyMessageQueue (INotifiableQueue) and ValkeyEventStream - Non-Valkey transports fall back to 1s polling via QueueWaitExtensions Increase heartbeat interval from 10s to 45s across all transport options, with corresponding health threshold adjustments (stale: 135s, degraded: 90s). Expected idle CPU reduction: ~58% → ~3-5%. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,7 @@ public sealed class StellaRouterOptionsTests
|
||||
Assert.Equal(AuthorizationMappingStrategy.Hybrid, options.AuthorizationMapping);
|
||||
Assert.Equal(MissingAuthorizationBehavior.WarnAndAllow, options.OnMissingAuthorization);
|
||||
Assert.Equal(TimeSpan.FromSeconds(30), options.DefaultTimeout);
|
||||
Assert.Equal(TimeSpan.FromSeconds(10), options.HeartbeatInterval);
|
||||
Assert.Equal(TimeSpan.FromSeconds(45), options.HeartbeatInterval);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -43,24 +43,24 @@ public sealed class InMemoryTransportOptionsTests
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Constructor_HeartbeatInterval_Is10Seconds()
|
||||
public void Constructor_HeartbeatInterval_Is45Seconds()
|
||||
{
|
||||
// Arrange & Act
|
||||
var options = new InMemoryTransportOptions();
|
||||
|
||||
// Assert
|
||||
options.HeartbeatInterval.Should().Be(TimeSpan.FromSeconds(10));
|
||||
options.HeartbeatInterval.Should().Be(TimeSpan.FromSeconds(45));
|
||||
}
|
||||
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Constructor_HeartbeatTimeout_Is30Seconds()
|
||||
public void Constructor_HeartbeatTimeout_Is135Seconds()
|
||||
{
|
||||
// Arrange & Act
|
||||
var options = new InMemoryTransportOptions();
|
||||
|
||||
// Assert
|
||||
options.HeartbeatTimeout.Should().Be(TimeSpan.FromSeconds(30));
|
||||
options.HeartbeatTimeout.Should().Be(TimeSpan.FromSeconds(135));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user