Skip to content

Commit

Permalink
[MM-61786] Reduce number of open file descriptors (#908) (#911)
Browse files Browse the repository at this point in the history
* Reduce number of open file descriptors

* Update test

* Update rtcd
  • Loading branch information
streamer45 authored Dec 2, 2024
1 parent dbd50f9 commit b63fe03
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3
github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef7b4
github.com/mattermost/morph v1.1.0
github.com/mattermost/rtcd v0.18.0
github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16
github.com/mattermost/squirrel v0.2.0
github.com/pkg/errors v0.9.1
github.com/rudderlabs/analytics-go v3.3.3+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef
github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef7b4/go.mod h1:PDPb/iqzJJ5ZvK/m70oDF55AXN/cOvVFj96Yu4e6j+Q=
github.com/mattermost/morph v1.1.0 h1:Q9vrJbeM3s2jfweGheq12EFIzdNp9a/6IovcbvOQ6Cw=
github.com/mattermost/morph v1.1.0/go.mod h1:gD+EaqX2UMyyuzmF4PFh4r33XneQ8Nzi+0E8nXjMa3A=
github.com/mattermost/rtcd v0.18.0 h1:Wxbl8r8cq8hD4ufg0XUGXM8lHPzxNW73fw4SngCuJ+A=
github.com/mattermost/rtcd v0.18.0/go.mod h1:FVyFLa+7dWImCZ+0g9xoc/1fMRKMuXs6yAZP1mDKBIg=
github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16 h1:3LonE6UDF+GT4LjC1hqPL1xLBORoHdxeid1VNmmZkIE=
github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16/go.mod h1:FVyFLa+7dWImCZ+0g9xoc/1fMRKMuXs6yAZP1mDKBIg=
github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8=
github.com/mattermost/squirrel v0.2.0/go.mod h1:NPPtk+CdpWre4GxMGoOpzEVFVc0ZoEFyJBZGCtn9nSU=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down
66 changes: 32 additions & 34 deletions server/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/mattermost/mattermost-plugin-calls/server/cluster"
"github.com/mattermost/mattermost-plugin-calls/server/enterprise"
Expand Down Expand Up @@ -157,50 +158,47 @@ func (p *Plugin) OnActivate() (retErr error) {
p.LogDebug("rtcd client manager initialized successfully")

p.rtcdManager = rtcdManager
} else {
rtcServerConfig := rtc.ServerConfig{
ICEAddressUDP: cfg.UDPServerAddress,
ICEAddressTCP: cfg.TCPServerAddress,
ICEPortUDP: *cfg.UDPServerPort,
ICEPortTCP: *cfg.TCPServerPort,
ICEHostOverride: cfg.ICEHostOverride,
ICEServers: rtc.ICEServers(cfg.getICEServers(false)),
TURNConfig: rtc.TURNConfig{
CredentialsExpirationMinutes: *cfg.TURNCredentialsExpirationMinutes,
},
EnableIPv6: *cfg.EnableIPv6,
UDPSocketsCount: runtime.NumCPU(),
}
if *cfg.ServerSideTURN {
rtcServerConfig.TURNConfig.StaticAuthSecret = cfg.TURNStaticAuthSecret
}
if cfg.ICEHostPortOverride != nil {
rtcServerConfig.ICEHostPortOverride = rtc.ICEHostPortOverride(fmt.Sprintf("%d", *cfg.ICEHostPortOverride))
}
rtcServer, err := rtc.NewServer(rtcServerConfig, newLogger(p), p.metrics.RTCMetrics())
if err != nil {
p.LogError(err.Error())
return err
}

go p.clusterEventsHandler()

p.LogDebug("activated", "ClusterID", status.ClusterId)

return nil
}
if err := rtcServer.Start(); err != nil {
p.LogError(err.Error())
return err
}

rtcServerConfig := rtc.ServerConfig{
ICEAddressUDP: cfg.UDPServerAddress,
ICEAddressTCP: cfg.TCPServerAddress,
ICEPortUDP: *cfg.UDPServerPort,
ICEPortTCP: *cfg.TCPServerPort,
ICEHostOverride: cfg.ICEHostOverride,
ICEServers: rtc.ICEServers(cfg.getICEServers(false)),
TURNConfig: rtc.TURNConfig{
CredentialsExpirationMinutes: *cfg.TURNCredentialsExpirationMinutes,
},
EnableIPv6: *cfg.EnableIPv6,
}
if *cfg.ServerSideTURN {
rtcServerConfig.TURNConfig.StaticAuthSecret = cfg.TURNStaticAuthSecret
}
if cfg.ICEHostPortOverride != nil {
rtcServerConfig.ICEHostPortOverride = rtc.ICEHostPortOverride(fmt.Sprintf("%d", *cfg.ICEHostPortOverride))
}
rtcServer, err := rtc.NewServer(rtcServerConfig, newLogger(p), p.metrics.RTCMetrics())
if err != nil {
p.LogError(err.Error())
return err
}
p.rtcServer = rtcServer

if err := rtcServer.Start(); err != nil {
p.LogError(err.Error())
return err
go p.wsWriter()
}

p.mut.Lock()
p.nodeID = status.ClusterId
p.rtcServer = rtcServer
p.mut.Unlock()

go p.clusterEventsHandler()
go p.wsWriter()

p.LogDebug("activated", "ClusterID", status.ClusterId)

Expand Down
6 changes: 4 additions & 2 deletions server/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
"runtime"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -678,8 +679,9 @@ func TestHandleJoin(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything, mock.Anything)

rtcServer, err := rtc.NewServer(rtc.ServerConfig{
ICEPortUDP: 33443,
ICEPortTCP: 33443,
ICEPortUDP: 33443,
ICEPortTCP: 33443,
UDPSocketsCount: runtime.NumCPU(),
}, newLogger(&p), p.metrics.RTCMetrics())
require.NoError(t, err)

Expand Down

0 comments on commit b63fe03

Please sign in to comment.