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
+24
View File
@@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"runtime"
"time"
"github.com/mitchellh/go-homedir"
@@ -12,6 +13,12 @@ import (
"gopkg.in/yaml.v3"
)
const (
defaultLimitNumTracksPerCPU int32 = 400
defaultLimitMaxNumTracks int32 = 8000
defaultLimitBytesPerSec float32 = 1_000_000_000 // just under 10 Gbps
)
var DefaultStunServers = []string{
"stun.l.google.com:19302",
"stun1.l.google.com:19302",
@@ -31,6 +38,7 @@ type Config struct {
Keys map[string]string `yaml:"keys"`
Region string `yaml:"region"`
LogLevel string `yaml:"log_level"`
Limit LimitConfig `yaml:"limit"`
Development bool `yaml:"development"`
}
@@ -123,6 +131,11 @@ type RegionConfig struct {
Lon float64 `yaml:"lon"`
}
type LimitConfig struct {
NumTracks int32 `yaml:"num_tracks"`
BytesPerSec float32 `yaml:"bytes_per_sec"`
}
func NewConfig(confString string, c *cli.Context) (*Config, error) {
// start with defaults
conf := &Config{
@@ -205,6 +218,17 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) {
}
}
if conf.Limit.NumTracks == 0 {
conf.Limit.NumTracks = defaultLimitNumTracksPerCPU * int32(runtime.NumCPU())
if conf.Limit.NumTracks > defaultLimitMaxNumTracks {
conf.Limit.NumTracks = defaultLimitMaxNumTracks
}
}
if conf.Limit.BytesPerSec == 0 {
conf.Limit.BytesPerSec = defaultLimitBytesPerSec
}
return conf, nil
}