perf: batch gateway submits and isolate callbacks

This commit is contained in:
hectorzhao
2026-08-25 11:39:59 +08:00
parent c6f11014d6
commit 761c123b65
29 changed files with 1912 additions and 193 deletions
+6 -1
View File
@@ -23,6 +23,7 @@ const (
type Manager struct {
APIBaseURL string
EventAPIBaseURL string
HTTPClient *http.Client
SubmitSegmentPublisher SubmitSegmentPublisher
@@ -170,11 +171,15 @@ func (m *Manager) ConnectionCounts() (desired int, connected int) {
}
func (m *Manager) newConnectionPool(channelID string, connectionID string, config queue.UpstreamConfig) *connectionPool {
eventAPIBaseURL := m.EventAPIBaseURL
if eventAPIBaseURL == "" {
eventAPIBaseURL = m.APIBaseURL
}
return &connectionPool{
channelID: channelID,
connectionID: connectionID,
config: config,
apiBaseURL: m.APIBaseURL,
apiBaseURL: eventAPIBaseURL,
httpClient: m.HTTPClient,
reporter: func(ctx context.Context, state ConnectionState) error {
return m.post(ctx, "/admin/gateway/connections", state)
+11
View File
@@ -85,6 +85,17 @@ func TestNormalizeUpstreamConfigDefaults(t *testing.T) {
}
}
func TestManagerSeparatesConnectionStateAndSupplierEventAPIs(t *testing.T) {
manager := &Manager{APIBaseURL: "http://main-api/api", EventAPIBaseURL: "http://callback-api/api"}
pool := manager.newConnectionPool("channel-1", "channel-1:primary", queue.UpstreamConfig{DesiredConnections: 1})
if pool.apiBaseURL != manager.EventAPIBaseURL {
t.Fatalf("supplier events must use callback API, got %q", pool.apiBaseURL)
}
if manager.APIBaseURL == pool.apiBaseURL {
t.Fatal("connection-state control API must remain separate from supplier events")
}
}
func queueUpstreamConfigForTest() queue.UpstreamConfig {
return queue.UpstreamConfig{
GatewayHost: "127.0.0.1",