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
This commit is contained in:
Mathew Kamkar
2021-11-23 15:48:07 -08:00
committed by GitHub
parent 5cdb1c4848
commit e3c91de594
10 changed files with 117 additions and 16 deletions
+41 -7
View File
@@ -15,24 +15,58 @@ import (
)
func TestCreateRoom(t *testing.T) {
ra, conf := newTestRoomAllocator(t)
t.Run("ensure default room settings are applied", func(t *testing.T) {
conf, err := config.NewConfig("", nil)
require.NoError(t, err)
node, err := routing.NewLocalNode(conf)
require.NoError(t, err)
ra, conf := newTestRoomAllocator(t, conf, node)
room, err := ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "myroom"})
require.NoError(t, err)
require.Equal(t, conf.Room.EmptyTimeout, room.EmptyTimeout)
require.NotEmpty(t, room.EnabledCodecs)
})
t.Run("reject new participants when track limit has been reached", func(t *testing.T) {
conf, err := config.NewConfig("", nil)
require.NoError(t, err)
conf.Limit.NumTracks = 10
node, err := routing.NewLocalNode(conf)
require.NoError(t, err)
node.Stats.NumTracksIn = 100
node.Stats.NumTracksOut = 100
ra, conf := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
})
t.Run("reject new participants when bandwidth limit has been reached", func(t *testing.T) {
conf, err := config.NewConfig("", nil)
require.NoError(t, err)
conf.Limit.BytesPerSec = 100
node, err := routing.NewLocalNode(conf)
require.NoError(t, err)
node.Stats.BytesInPerSec = 1000
node.Stats.BytesOutPerSec = 1000
ra, conf := newTestRoomAllocator(t, conf, node)
_, err = ra.CreateRoom(context.Background(), &livekit.CreateRoomRequest{Name: "low-limit-room"})
require.ErrorIs(t, err, routing.ErrNodeLimitReached)
})
}
func newTestRoomAllocator(t *testing.T) (service.RoomAllocator, *config.Config) {
func newTestRoomAllocator(t *testing.T, conf *config.Config, node *livekit.Node) (service.RoomAllocator, *config.Config) {
store := &servicefakes.FakeRoomStore{}
store.LoadRoomReturns(nil, service.ErrRoomNotFound)
router := &routingfakes.FakeRouter{}
conf, err := config.NewConfig("", nil)
require.NoError(t, err)
node, err := routing.NewLocalNode(conf)
require.NoError(t, err)
router.GetNodeForRoomReturns(node, nil)