Add batch i/o to improve throughput (#2033)
* Add batch i/o to improve throughput * remove empty line * Solve comments * Change rtcconfig.UDPPort to PortRange * Fix test
This commit is contained in:
@@ -55,8 +55,9 @@ func printPorts(c *cli.Context) error {
|
|||||||
if conf.RTC.TCPPort != 0 {
|
if conf.RTC.TCPPort != 0 {
|
||||||
tcpPorts = append(tcpPorts, fmt.Sprintf("%d - ICE/TCP", conf.RTC.TCPPort))
|
tcpPorts = append(tcpPorts, fmt.Sprintf("%d - ICE/TCP", conf.RTC.TCPPort))
|
||||||
}
|
}
|
||||||
if conf.RTC.UDPPort != 0 {
|
if conf.RTC.UDPPort.Valid() {
|
||||||
udpPorts = append(udpPorts, fmt.Sprintf("%d - ICE/UDP", conf.RTC.UDPPort))
|
portStr, _ := conf.RTC.UDPPort.MarshalYAML()
|
||||||
|
udpPorts = append(udpPorts, fmt.Sprintf("%s - ICE/UDP", portStr))
|
||||||
} else {
|
} else {
|
||||||
udpPorts = append(udpPorts, fmt.Sprintf("%d-%d - ICE/UDP range", conf.RTC.ICEPortRangeStart, conf.RTC.ICEPortRangeEnd))
|
udpPorts = append(udpPorts, fmt.Sprintf("%d-%d - ICE/UDP range", conf.RTC.ICEPortRangeStart, conf.RTC.ICEPortRangeEnd))
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc"
|
"github.com/livekit/livekit-server/pkg/rtc"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
|
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
@@ -206,7 +207,7 @@ func getConfig(c *cli.Context) (*config.Config, error) {
|
|||||||
|
|
||||||
if c.String("config") == "" && c.String("config-body") == "" && conf.Development {
|
if c.String("config") == "" && c.String("config-body") == "" && conf.Development {
|
||||||
// use single port UDP when no config is provided
|
// use single port UDP when no config is provided
|
||||||
conf.RTC.UDPPort = 7882
|
conf.RTC.UDPPort = rtcconfig.PortRange{Start: 7882}
|
||||||
conf.RTC.ICEPortRangeStart = 0
|
conf.RTC.ICEPortRangeStart = 0
|
||||||
conf.RTC.ICEPortRangeEnd = 0
|
conf.RTC.ICEPortRangeEnd = 0
|
||||||
logger.Infow("starting in development mode")
|
logger.Infow("starting in development mode")
|
||||||
|
|||||||
+8
-3
@@ -43,10 +43,10 @@ rtc:
|
|||||||
# that maps to an external one
|
# that maps to an external one
|
||||||
use_external_ip: true
|
use_external_ip: true
|
||||||
# # when set, LiveKit will attempt to use a UDP mux so all UDP traffic goes through
|
# # when set, LiveKit will attempt to use a UDP mux so all UDP traffic goes through
|
||||||
# # a single port. This simplifies deployment, but mux will become an overhead for
|
# # listed port(s). To maximize system performance, we recommend using a range of ports
|
||||||
# # highly trafficked deployments.
|
# # greater or equal to the number of vCPUs on the machine.
|
||||||
# # port_range_start & end must not be set for this config to take effect
|
# # port_range_start & end must not be set for this config to take effect
|
||||||
# udp_port: 7882
|
# udp_port: 7882-7892
|
||||||
# # when set to true, server will use a lite ice agent, that will speed up ice connection, but
|
# # when set to true, server will use a lite ice agent, that will speed up ice connection, but
|
||||||
# # might cause connect issue if server running behind NAT.
|
# # might cause connect issue if server running behind NAT.
|
||||||
# use_ice_lite: true
|
# use_ice_lite: true
|
||||||
@@ -107,6 +107,11 @@ rtc:
|
|||||||
# # are disabled and clients don't ACK opened peer connections, only reliable, ordered delivery
|
# # are disabled and clients don't ACK opened peer connections, only reliable, ordered delivery
|
||||||
# # will be available.
|
# # will be available.
|
||||||
# strict_acks: true
|
# strict_acks: true
|
||||||
|
# # enable batch write to merge network write system calls to reduce cpu usage. Outgoing packets
|
||||||
|
# # will be queued until length of queue equal to `batch_size` or time elapsed since last write exceeds `max_flush_interval`.
|
||||||
|
# batch_io:
|
||||||
|
# batch_size: 128
|
||||||
|
# max_flush_interval: 2ms
|
||||||
|
|
||||||
# when enabled, LiveKit will expose prometheus metrics on :6789/metrics
|
# when enabled, LiveKit will expose prometheus metrics on :6789/metrics
|
||||||
# prometheus_port: 6789
|
# prometheus_port: 6789
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ require (
|
|||||||
github.com/hashicorp/golang-lru/v2 v2.0.5
|
github.com/hashicorp/golang-lru/v2 v2.0.5
|
||||||
github.com/jxskiss/base62 v1.1.0
|
github.com/jxskiss/base62 v1.1.0
|
||||||
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
|
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20230823131232-12f579dc9af0
|
github.com/livekit/mediatransportutil v0.0.0-20230905070227-1decac7a3c61
|
||||||
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86
|
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86
|
||||||
github.com/livekit/psrpc v0.3.3
|
github.com/livekit/psrpc v0.3.3
|
||||||
github.com/mackerelio/go-osstat v0.2.4
|
github.com/mackerelio/go-osstat v0.2.4
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ github.com/lithammer/shortuuid/v4 v4.0.0 h1:QRbbVkfgNippHOS8PXDkti4NaWeyYfcBTHtw
|
|||||||
github.com/lithammer/shortuuid/v4 v4.0.0/go.mod h1:Zs8puNcrvf2rV9rTH51ZLLcj7ZXqQI3lv67aw4KiB1Y=
|
github.com/lithammer/shortuuid/v4 v4.0.0/go.mod h1:Zs8puNcrvf2rV9rTH51ZLLcj7ZXqQI3lv67aw4KiB1Y=
|
||||||
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkDaKb5iXdynYrzB84ErPPO4LbRASk58=
|
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkDaKb5iXdynYrzB84ErPPO4LbRASk58=
|
||||||
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
|
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20230823131232-12f579dc9af0 h1:cHNvPzn6VHFcsHx8ZC9LwU/4jj22mW3LILrNg/y5A6I=
|
github.com/livekit/mediatransportutil v0.0.0-20230905070227-1decac7a3c61 h1:B03f6QRPP8ESgthh4FdV6RTrW+ukEePMi4uDdAnJxKQ=
|
||||||
github.com/livekit/mediatransportutil v0.0.0-20230823131232-12f579dc9af0/go.mod h1:xirUXW8xnLGmfCwUeAv/nj1VGo1OO1BmgxrYP7jK/14=
|
github.com/livekit/mediatransportutil v0.0.0-20230905070227-1decac7a3c61/go.mod h1:njHoM3uTstzLF5N/FyzZ96+TYdJkgeyRbCWBWBiyS2s=
|
||||||
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86 h1:QEzGhfIOmGdRw17xIldbYzb1MTsYuVfXSqz8FTyfjWQ=
|
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86 h1:QEzGhfIOmGdRw17xIldbYzb1MTsYuVfXSqz8FTyfjWQ=
|
||||||
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86/go.mod h1:/JuO+G/btZ5gNwX2+901L6za3UvVO6DHRXHsv8kkLsU=
|
github.com/livekit/protocol v1.6.2-0.20230828184341-dfb5162c7c86/go.mod h1:/JuO+G/btZ5gNwX2+901L6za3UvVO6DHRXHsv8kkLsU=
|
||||||
github.com/livekit/psrpc v0.3.3 h1:+lltbuN39IdaynXhLLxRShgYqYsRMWeeXKzv60oqyWo=
|
github.com/livekit/psrpc v0.3.3 h1:+lltbuN39IdaynXhLLxRShgYqYsRMWeeXKzv60oqyWo=
|
||||||
|
|||||||
@@ -308,7 +308,6 @@ var DefaultConfig = Config{
|
|||||||
RTCConfig: rtcconfig.RTCConfig{
|
RTCConfig: rtcconfig.RTCConfig{
|
||||||
UseExternalIP: false,
|
UseExternalIP: false,
|
||||||
TCPPort: 7881,
|
TCPPort: 7881,
|
||||||
UDPPort: 0,
|
|
||||||
ICEPortRangeStart: 0,
|
ICEPortRangeStart: 0,
|
||||||
ICEPortRangeEnd: 0,
|
ICEPortRangeEnd: 0,
|
||||||
STUNServers: []string{},
|
STUNServers: []string{},
|
||||||
@@ -802,7 +801,7 @@ func (conf *Config) updateFromCLI(c *cli.Context, baseFlags []cli.Flag) error {
|
|||||||
conf.RTC.NodeIP = c.String("node-ip")
|
conf.RTC.NodeIP = c.String("node-ip")
|
||||||
}
|
}
|
||||||
if c.IsSet("udp-port") {
|
if c.IsSet("udp-port") {
|
||||||
conf.RTC.UDPPort = uint32(c.Int("udp-port"))
|
conf.RTC.UDPPort = rtcconfig.PortRange{Start: (c.Int("udp-port"))}
|
||||||
}
|
}
|
||||||
if c.IsSet("bind") {
|
if c.IsSet("bind") {
|
||||||
conf.BindAddresses = c.StringSlice("bind")
|
conf.BindAddresses = c.StringSlice("bind")
|
||||||
|
|||||||
@@ -661,7 +661,6 @@ func newParticipantForTestWithOpts(identity livekit.ParticipantIdentity, opts *p
|
|||||||
}
|
}
|
||||||
conf, _ := config.NewConfig("", true, nil, nil)
|
conf, _ := config.NewConfig("", true, nil, nil)
|
||||||
// disable mux, it doesn't play too well with unit test
|
// disable mux, it doesn't play too well with unit test
|
||||||
conf.RTC.UDPPort = 0
|
|
||||||
conf.RTC.TCPPort = 0
|
conf.RTC.TCPPort = 0
|
||||||
rtcConf, err := NewWebRTCConfig(conf)
|
rtcConf, err := NewWebRTCConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
|||||||
_ = r.refreshToken(participant)
|
_ = r.refreshToken(participant)
|
||||||
tokenTicker := time.NewTicker(tokenRefreshInterval)
|
tokenTicker := time.NewTicker(tokenRefreshInterval)
|
||||||
defer tokenTicker.Stop()
|
defer tokenTicker.Stop()
|
||||||
stateCheckTicker := time.NewTicker(time.Millisecond * 50)
|
stateCheckTicker := time.NewTicker(time.Millisecond * 500)
|
||||||
defer stateCheckTicker.Stop()
|
defer stateCheckTicker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ func (s *LivekitServer) Start() error {
|
|||||||
if s.config.RTC.TCPPort != 0 {
|
if s.config.RTC.TCPPort != 0 {
|
||||||
values = append(values, "rtc.portTCP", s.config.RTC.TCPPort)
|
values = append(values, "rtc.portTCP", s.config.RTC.TCPPort)
|
||||||
}
|
}
|
||||||
if !s.config.RTC.ForceTCP && s.config.RTC.UDPPort != 0 {
|
if !s.config.RTC.ForceTCP && s.config.RTC.UDPPort.Valid() {
|
||||||
values = append(values, "rtc.portUDP", s.config.RTC.UDPPort)
|
values = append(values, "rtc.portUDP", s.config.RTC.UDPPort)
|
||||||
} else {
|
} else {
|
||||||
values = append(values,
|
values = append(values,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
"github.com/livekit/livekit-server/pkg/testutils"
|
"github.com/livekit/livekit-server/pkg/testutils"
|
||||||
testclient "github.com/livekit/livekit-server/test/client"
|
testclient "github.com/livekit/livekit-server/test/client"
|
||||||
|
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
@@ -178,7 +179,7 @@ func createMultiNodeServer(nodeID string, port uint32) *service.LivekitServer {
|
|||||||
panic(fmt.Sprintf("could not create config: %v", err))
|
panic(fmt.Sprintf("could not create config: %v", err))
|
||||||
}
|
}
|
||||||
conf.Port = port
|
conf.Port = port
|
||||||
conf.RTC.UDPPort = port + 1
|
conf.RTC.UDPPort = rtcconfig.PortRange{Start: int(port) + 1}
|
||||||
conf.RTC.TCPPort = port + 2
|
conf.RTC.TCPPort = port + 2
|
||||||
conf.Redis.Address = "localhost:6379"
|
conf.Redis.Address = "localhost:6379"
|
||||||
conf.Keys = map[string]string{testApiKey: testApiSecret}
|
conf.Keys = map[string]string{testApiKey: testApiSecret}
|
||||||
|
|||||||
Reference in New Issue
Block a user