Improve frequency of stats update (#673)

* Improve frequency of stats update

Prometheus stats are updated as the data becomes available, instead of
aggregated along with telemetry batches. Node availability decisions can
now react much faster to these stats.

* use the same intervals for connection quality updates
This commit is contained in:
David Zhao
2022-05-09 08:55:06 -07:00
committed by GitHub
parent 16407ea180
commit bd7e3beda4
3 changed files with 16 additions and 30 deletions
+4 -4
View File
@@ -14,7 +14,7 @@ import (
)
const (
connectionQualityUpdateInterval = 5 * time.Second
UpdateInterval = 2 * time.Second
)
type ConnectionStatsParams struct {
@@ -47,7 +47,7 @@ func NewConnectionStats(params ConnectionStatsParams) *ConnectionStats {
}
func (cs *ConnectionStats) Start() {
go cs.updateStats()
go cs.updateStatsWorker()
}
func (cs *ConnectionStats) Close() {
@@ -127,10 +127,10 @@ func (cs *ConnectionStats) getStat() *livekit.AnalyticsStat {
}
}
func (cs *ConnectionStats) updateStats() {
func (cs *ConnectionStats) updateStatsWorker() {
interval := cs.params.UpdateInterval
if interval == 0 {
interval = connectionQualityUpdateInterval
interval = UpdateInterval
}
tk := time.NewTicker(interval)