Batch subscriber updates to reduce noise (#703)

Improve scalability by batching subscriber updates on an interval.
When lots of subscribers join, the server ends up spending 20% CPU
sending each state change to everyone. There's a non-trivial amount of
overhead with each send operation.

For publishers, updates are sent right away.
This commit is contained in:
David Zhao
2022-05-20 22:54:02 -07:00
committed by GitHub
parent 8ef53037eb
commit cdf1724d80
4 changed files with 98 additions and 24 deletions
+5 -4
View File
@@ -8,7 +8,7 @@ import (
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
)
func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.ProtocolVersion, hidden bool) *typesfakes.FakeLocalParticipant {
func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.ProtocolVersion, hidden bool, publisher bool) *typesfakes.FakeLocalParticipant {
p := &typesfakes.FakeLocalParticipant{}
sid := utils.NewGuid(utils.ParticipantPrefix)
p.IDReturns(livekit.ParticipantID(sid))
@@ -20,9 +20,10 @@ func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.Pro
p.CanPublishDataReturns(!hidden)
p.HiddenReturns(hidden)
p.ToProtoReturns(&livekit.ParticipantInfo{
Sid: sid,
Identity: string(identity),
State: livekit.ParticipantInfo_JOINED,
Sid: sid,
Identity: string(identity),
State: livekit.ParticipantInfo_JOINED,
IsPublisher: publisher,
})
p.SetMetadataStub = func(m string) {