Detach subscriber datachannel to save memory (#2680)
Sfu don't read message from subscriber datachannel, detach it to bypass the readLoop can save 128KB memory and 2 goroutines per participant.
This commit is contained in:
+19
-7
@@ -53,7 +53,6 @@ import (
|
|||||||
sfuutils "github.com/livekit/livekit-server/pkg/sfu/utils"
|
sfuutils "github.com/livekit/livekit-server/pkg/sfu/utils"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
"github.com/livekit/livekit-server/pkg/utils"
|
"github.com/livekit/livekit-server/pkg/utils"
|
||||||
sutils "github.com/livekit/livekit-server/pkg/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -75,8 +74,6 @@ const (
|
|||||||
minConnectTimeoutAfterICE = 10 * time.Second
|
minConnectTimeoutAfterICE = 10 * time.Second
|
||||||
maxConnectTimeoutAfterICE = 20 * time.Second // max duration for waiting pc to connect after ICE is connected
|
maxConnectTimeoutAfterICE = 20 * time.Second // max duration for waiting pc to connect after ICE is connected
|
||||||
|
|
||||||
maxICECandidates = 20
|
|
||||||
|
|
||||||
shortConnectionThreshold = 90 * time.Second
|
shortConnectionThreshold = 90 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -185,7 +182,7 @@ type PCTransport struct {
|
|||||||
preferTCP atomic.Bool
|
preferTCP atomic.Bool
|
||||||
isClosed atomic.Bool
|
isClosed atomic.Bool
|
||||||
|
|
||||||
eventsQueue *sutils.TypedOpsQueue[event]
|
eventsQueue *utils.TypedOpsQueue[event]
|
||||||
|
|
||||||
// the following should be accessed only in event processing go routine
|
// the following should be accessed only in event processing go routine
|
||||||
cacheLocalCandidates bool
|
cacheLocalCandidates bool
|
||||||
@@ -305,6 +302,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
|||||||
|
|
||||||
ir := &interceptor.Registry{}
|
ir := &interceptor.Registry{}
|
||||||
if params.IsSendSide {
|
if params.IsSendSide {
|
||||||
|
se.DetachDataChannels()
|
||||||
if params.CongestionControlConfig.UseSendSideBWE {
|
if params.CongestionControlConfig.UseSendSideBWE {
|
||||||
gf, err := cc.NewInterceptor(func() (cc.BandwidthEstimator, error) {
|
gf, err := cc.NewInterceptor(func() (cc.BandwidthEstimator, error) {
|
||||||
return gcc.NewSendSideBWE(
|
return gcc.NewSendSideBWE(
|
||||||
@@ -390,7 +388,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
params: params,
|
params: params,
|
||||||
debouncedNegotiate: debounce.New(negotiationFrequency),
|
debouncedNegotiate: debounce.New(negotiationFrequency),
|
||||||
negotiationState: transport.NegotiationStateNone,
|
negotiationState: transport.NegotiationStateNone,
|
||||||
eventsQueue: sutils.NewTypedOpsQueue[event](utils.OpsQueueParams{
|
eventsQueue: utils.NewTypedOpsQueue[event](utils.OpsQueueParams{
|
||||||
Name: "transport",
|
Name: "transport",
|
||||||
MinSize: 64,
|
MinSize: 64,
|
||||||
Logger: params.Logger,
|
Logger: params.Logger,
|
||||||
@@ -402,7 +400,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
if params.IsSendSide {
|
if params.IsSendSide {
|
||||||
t.streamAllocator = streamallocator.NewStreamAllocator(streamallocator.StreamAllocatorParams{
|
t.streamAllocator = streamallocator.NewStreamAllocator(streamallocator.StreamAllocatorParams{
|
||||||
Config: params.CongestionControlConfig,
|
Config: params.CongestionControlConfig,
|
||||||
Logger: params.Logger.WithComponent(sutils.ComponentCongestionControl),
|
Logger: params.Logger.WithComponent(utils.ComponentCongestionControl),
|
||||||
})
|
})
|
||||||
t.streamAllocator.OnStreamStateChange(params.Handler.OnStreamStateChange)
|
t.streamAllocator.OnStreamStateChange(params.Handler.OnStreamStateChange)
|
||||||
t.streamAllocator.Start()
|
t.streamAllocator.Start()
|
||||||
@@ -855,8 +853,22 @@ func (t *PCTransport) CreateDataChannel(label string, dci *webrtc.DataChannelIni
|
|||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
*dcPtr = dc
|
*dcPtr = dc
|
||||||
if t.params.DirectionConfig.StrictACKs {
|
if t.params.DirectionConfig.StrictACKs {
|
||||||
dc.OnOpen(dcReadyHandler)
|
dc.OnOpen(func() {
|
||||||
|
if t.params.IsSendSide {
|
||||||
|
if _, err := dc.Detach(); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to detach data channel", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dcReadyHandler()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
|
dc.OnOpen(func() {
|
||||||
|
if t.params.IsSendSide {
|
||||||
|
if _, err := dc.Detach(); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to detach data channel", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
dc.OnDial(dcReadyHandler)
|
dc.OnDial(dcReadyHandler)
|
||||||
}
|
}
|
||||||
dc.OnClose(dcCloseHandler)
|
dc.OnClose(dcCloseHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user