downstream allocator (#155)
* WIP branch to hash out down stream allocator. * Plug more bits of stream allocator * update protocol * remove SignalRequest_Simulcast (#154) * Plug more bits of stream allocator * Handle simulcast track available layers change * WIP branch to hash out down stream allocator. * Plug more bits of stream allocator * Handle simulcast track available layers change * Adopt signature of call to AdjustAllocation * Move StreamAllocator to PCTransport and allocate only for subscriber. * Move streamallocator to ion-sfu * Start/Stop of streamallocator * Use StreamAllocator for subscriber bandwidth management. * Do not allocate in ADD_TRACK * Set payload in constructor * - Add some logging - Protocol message to notify clients of paused/resumed streams * named return * oops correct sense of isPausing * Update pkg/sfu/streamallocator.go Committing David's suggestion. Co-authored-by: David Zhao <david@davidzhao.com> * - Log estimate changes/commits. - Catch more than epsilon change oscillating for long time. Co-authored-by: David Colburn <xero73@gmail.com> Co-authored-by: David Zhao <david@davidzhao.com>
This commit is contained in:
co-authored by
David Colburn
David Zhao
parent
9aff9af690
commit
98695cdd22
+42
-6
@@ -107,13 +107,24 @@
|
||||
package sfu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gammazero/deque"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
type ProberParams struct {
|
||||
ParticipantID string
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
type Prober struct {
|
||||
participantID string
|
||||
logger logger.Logger
|
||||
|
||||
clustersMu sync.RWMutex
|
||||
clusters deque.Deque
|
||||
activeCluster *Cluster
|
||||
@@ -121,8 +132,11 @@ type Prober struct {
|
||||
onSendProbe func(bytesToSend int) int
|
||||
}
|
||||
|
||||
func NewProber() *Prober {
|
||||
p := &Prober{}
|
||||
func NewProber(params ProberParams) *Prober {
|
||||
p := &Prober{
|
||||
participantID: params.ParticipantID,
|
||||
logger: params.Logger,
|
||||
}
|
||||
p.clusters.SetMinCapacity(2)
|
||||
return p
|
||||
}
|
||||
@@ -136,9 +150,14 @@ func (p *Prober) IsRunning() bool {
|
||||
|
||||
func (p *Prober) Reset() {
|
||||
p.clustersMu.Lock()
|
||||
// LK-TODO - log if active cluster is getting reset, maybe log state of all clusters
|
||||
defer p.clustersMu.Unlock()
|
||||
|
||||
if p.activeCluster != nil {
|
||||
p.logger.Debugw("resetting active cluster", "participant", p.participantID, "cluster", p.activeCluster.String())
|
||||
}
|
||||
|
||||
p.clusters.Clear()
|
||||
p.activeCluster = nil
|
||||
}
|
||||
|
||||
func (p *Prober) OnSendProbe(f func(bytesToSend int) int) {
|
||||
@@ -151,7 +170,7 @@ func (p *Prober) AddCluster(desiredRateBps int, expectedRateBps int, minDuration
|
||||
}
|
||||
|
||||
cluster := NewCluster(desiredRateBps, expectedRateBps, minDuration, maxDuration)
|
||||
// LK-TODO - log information about added cluster
|
||||
p.logger.Debugw("cluster added", "participant", p.participantID, "cluster", cluster.String())
|
||||
|
||||
p.pushBackClusterAndMaybeStart(cluster)
|
||||
}
|
||||
@@ -228,12 +247,15 @@ func (p *Prober) run() {
|
||||
}
|
||||
|
||||
if !cluster.Process(p) {
|
||||
p.logger.Debugw("cluster finished", "participant", p.participantID, "cluster", cluster.String())
|
||||
p.popFrontCluster(cluster)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
|
||||
type Cluster struct {
|
||||
// LK-TODO-START
|
||||
// Check if we can operate at cluster level without a lock.
|
||||
@@ -300,7 +322,6 @@ func (c *Cluster) Process(p *Prober) bool {
|
||||
// if already past deadline, end the cluster
|
||||
timeElapsed := time.Since(c.startTime)
|
||||
if timeElapsed > c.maxDuration {
|
||||
// LK-TODO log information about short fall in probing
|
||||
c.lock.RUnlock()
|
||||
return false
|
||||
}
|
||||
@@ -341,7 +362,6 @@ func (c *Cluster) Process(p *Prober) bool {
|
||||
// do not end cluster until minDuration elapses even if rate is achieved.
|
||||
// Ensures that the next cluster (if any) does not start early.
|
||||
if (c.bytesSentProbe+c.bytesSentNonProbe) >= c.desiredBytes && timeElapsed >= c.minDuration {
|
||||
// LK-TODO - log data about how much time the probe finished compared to min/max
|
||||
c.lock.Unlock()
|
||||
return false
|
||||
}
|
||||
@@ -350,3 +370,19 @@ func (c *Cluster) Process(p *Prober) bool {
|
||||
c.lock.Unlock()
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Cluster) String() string {
|
||||
activeTimeMs := time.Duration(0)
|
||||
if !c.startTime.IsZero() {
|
||||
activeTimeMs = time.Since(c.startTime) * time.Millisecond
|
||||
}
|
||||
|
||||
return fmt.Sprintf("bytes: desired %d / probe %d / non-probe %d / remaining: %d, time(ms): active %d / min %d / max %d",
|
||||
c.desiredBytes,
|
||||
c.bytesSentProbe,
|
||||
c.bytesSentNonProbe,
|
||||
c.desiredBytes-c.bytesSentProbe-c.bytesSentNonProbe,
|
||||
activeTimeMs,
|
||||
c.minDuration*time.Millisecond,
|
||||
c.maxDuration*time.Millisecond)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user