Files
livekit/pkg/routing/selector/utils.go
Mathew Kamkar e3c91de594 Configurable limit for number of tracks (#197)
* configurable node track limit

* sample config

* todos

* end of file new line

* default max num tracks

* bandwidth limit

* client message for limit exceeded node

* 10 Gbps default network limit
2021-11-23 15:48:07 -08:00

40 lines
1.1 KiB
Go

package selector
import (
"time"
"github.com/livekit/livekit-server/pkg/config"
livekit "github.com/livekit/protocol/proto"
"github.com/thoas/go-funk"
)
const AvailableSeconds = 5
// checks if a node has been updated recently to be considered for selection
func IsAvailable(node *livekit.Node) bool {
delta := time.Now().Unix() - node.Stats.UpdatedAt
return int(delta) < AvailableSeconds
}
func GetAvailableNodes(nodes []*livekit.Node) []*livekit.Node {
return funk.Filter(nodes, func(node *livekit.Node) bool {
return IsAvailable(node) && node.State == livekit.NodeState_SERVING
}).([]*livekit.Node)
}
// TODO: check remote node configured limit, instead of this node's config
func LimitsReached(limitConfig config.LimitConfig, nodeStats *livekit.NodeStats) bool {
if nodeStats == nil {
return false
}
if limitConfig.NumTracks > 0 && limitConfig.NumTracks <= nodeStats.NumTracksIn+nodeStats.NumTracksOut {
return true
}
if limitConfig.BytesPerSec > 0 && limitConfig.BytesPerSec <= nodeStats.BytesInPerSec+nodeStats.BytesOutPerSec {
return true
}
return false
}