Implement event loop for telemetry service (#297)
It allows all actions/events to run in the same go routine. Therefore no synchronization primitives are needed inside telemetry service implementation.
This commit is contained in:
@@ -2,7 +2,6 @@ package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/gammazero/workerpool"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
@@ -26,7 +25,6 @@ type telemetryServiceInternal struct {
|
||||
notifier webhook.Notifier
|
||||
webhookPool *workerpool.WorkerPool
|
||||
|
||||
sync.RWMutex
|
||||
// one worker per participant
|
||||
workers map[string]*StatsWorker
|
||||
|
||||
@@ -43,18 +41,14 @@ func NewTelemetryServiceInternal(notifier webhook.Notifier, analytics AnalyticsS
|
||||
}
|
||||
|
||||
func (t *telemetryServiceInternal) AddUpTrack(participantID string, trackID string, buff *buffer.Buffer) {
|
||||
t.RLock()
|
||||
w := t.workers[participantID]
|
||||
t.RUnlock()
|
||||
if w != nil {
|
||||
w.AddBuffer(trackID, buff)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryServiceInternal) OnDownstreamPacket(participantID string, trackID string, bytes int) {
|
||||
t.RLock()
|
||||
w := t.workers[participantID]
|
||||
t.RUnlock()
|
||||
if w != nil {
|
||||
w.OnDownstreamPacket(trackID, bytes)
|
||||
}
|
||||
@@ -90,9 +84,7 @@ func (t *telemetryServiceInternal) HandleRTCP(streamType livekit.StreamType, par
|
||||
|
||||
prometheus.IncrementRTCP(direction, stats.NackCount, stats.PliCount, stats.FirCount)
|
||||
|
||||
t.RLock()
|
||||
w := t.workers[participantID]
|
||||
t.RUnlock()
|
||||
if w != nil {
|
||||
w.OnRTCP(trackID, streamType, stats)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user