feat: tune websocket hub backpressure

This commit is contained in:
2026-09-20 20:53:50 +08:00
parent 850376624f
commit 478be069e6
16 changed files with 218 additions and 52 deletions

View File

@@ -70,11 +70,15 @@ func run() error {
defer metricsListener.Close()
metrics = observability.NewRegistry()
metrics.RecordRuntimeConfig(observability.RuntimeConfig{
WorkflowTickInterval: cfg.WorkflowTickInterval,
ScheduleTickInterval: cfg.ScheduleTickInterval,
RecoveryTickInterval: cfg.RecoveryTickInterval,
BatchLimit: cfg.RuntimeBatchLimit,
ShutdownTimeout: cfg.ShutdownTimeout,
WorkflowTickInterval: cfg.WorkflowTickInterval,
ScheduleTickInterval: cfg.ScheduleTickInterval,
RecoveryTickInterval: cfg.RecoveryTickInterval,
BatchLimit: cfg.RuntimeBatchLimit,
ShutdownTimeout: cfg.ShutdownTimeout,
WorkerConnectionLimit: cfg.WorkerConnectionLimit,
EventConnectionLimit: cfg.EventConnectionLimit,
DispatchWorkers: cfg.DispatchWorkers,
DispatchCapacity: cfg.DispatchCapacity,
})
metrics.RecordDatabase(db.Stats())
}
@@ -88,10 +92,18 @@ func run() error {
if err != nil {
return err
}
hub := httpserver.NewWorkerHub(root, worker.New(executions))
hub := httpserver.NewWorkerHub(root, worker.New(executions), httpserver.HubOptions{
ConnectionLimit: cfg.WorkerConnectionLimit,
DispatchWorkers: cfg.DispatchWorkers,
DispatchCapacity: cfg.DispatchCapacity,
})
httpserver.RegisterWorkers(server, hub)
eventService := events.New(mysql.NewEventStore(db))
eventHub := httpserver.NewEventHub(root, eventService)
eventHub := httpserver.NewEventHub(root, eventService, httpserver.HubOptions{
ConnectionLimit: cfg.EventConnectionLimit,
DispatchWorkers: cfg.DispatchWorkers,
DispatchCapacity: cfg.DispatchCapacity,
})
httpserver.RegisterEventSubscriptions(server, eventService)
httpserver.RegisterEventConsumers(server, eventHub)
defer func() {
@@ -250,7 +262,7 @@ func run() error {
slog.Info("Orbit metrics server starting", "metrics_address", metricsListener.Addr().String())
}
go func() { done <- server.Serve(listener) }()
slog.Info("Orbit HTTP server starting", "address", listener.Addr().String(), "scope", "health, task, queue, schedule, subscription, workflow and Worker APIs", "node_id", node, "workflow_tick_interval", cfg.WorkflowTickInterval.String(), "schedule_tick_interval", cfg.ScheduleTickInterval.String(), "recovery_tick_interval", cfg.RecoveryTickInterval.String(), "runtime_batch_limit", cfg.RuntimeBatchLimit, "shutdown_timeout", cfg.ShutdownTimeout.String())
slog.Info("Orbit HTTP server starting", "address", listener.Addr().String(), "scope", "health, task, queue, schedule, subscription, workflow and Worker APIs", "node_id", node, "workflow_tick_interval", cfg.WorkflowTickInterval.String(), "schedule_tick_interval", cfg.ScheduleTickInterval.String(), "recovery_tick_interval", cfg.RecoveryTickInterval.String(), "runtime_batch_limit", cfg.RuntimeBatchLimit, "shutdown_timeout", cfg.ShutdownTimeout.String(), "worker_connection_limit", cfg.WorkerConnectionLimit, "event_connection_limit", cfg.EventConnectionLimit, "dispatch_workers", cfg.DispatchWorkers, "dispatch_capacity", cfg.DispatchCapacity)
select {
case err := <-done:
if errors.Is(err, http.ErrServerClosed) {