perf(group): reduce websocket fanout serialization
This commit is contained in:
@@ -195,6 +195,9 @@ type Subscription struct {
|
||||
supd chan<- *sessionUpdate
|
||||
}
|
||||
|
||||
// sharedServerMessage is an immutable JSON payload reused by multiple WebSocket sessions.
|
||||
type sharedServerMessage []byte
|
||||
|
||||
func (s *Session) enqueueOutbound(payload any) bool {
|
||||
if s.isMultiplex() {
|
||||
return s.enqueueMultiplexOutbound(payload, multiplexEnqueueWait)
|
||||
@@ -234,8 +237,16 @@ func (s *Session) enqueueMultiplexOutbound(payload any, wait time.Duration) bool
|
||||
s.clusterQueueMu.Unlock()
|
||||
return true
|
||||
}
|
||||
if msg, ok := payload.(*ServerComMessage); ok {
|
||||
msg.clusterQueuedAt = time.Now()
|
||||
}
|
||||
select {
|
||||
case s.send <- payload:
|
||||
peer := "unknown"
|
||||
if s.clnode != nil {
|
||||
peer = s.clnode.name
|
||||
}
|
||||
immetrics.ObserveClusterM2PEnqueue(peer, len(s.send))
|
||||
s.clusterQueueMu.Unlock()
|
||||
return true
|
||||
default:
|
||||
@@ -525,6 +536,17 @@ func (s *Session) queueOutBytes(data []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Session) queueOutSharedBytes(data []byte) bool {
|
||||
if s == nil || atomic.LoadInt32(&s.terminating) > 0 {
|
||||
return true
|
||||
}
|
||||
if !s.enqueueOutbound(sharedServerMessage(data)) {
|
||||
logs.Err.Println("s.queueOutSharedBytes: session's send queue full", s.sid)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Session) maybeScheduleClusterWriteLoop() {
|
||||
if s.multi != nil {
|
||||
s.multi.scheduleClusterWriteLoop()
|
||||
|
||||
Reference in New Issue
Block a user