mirror of
https://github.com/datarhei/core.git
synced 2025-10-04 07:37:33 +08:00
Allow to set a soft memory limit for the binary itself
The setting debug.memory_limit_mbytes should not be used in conjuction with debug.force_gc because the memory limit influences the garbage collector.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
golog "log"
|
golog "log"
|
||||||
|
"math"
|
||||||
gonet "net"
|
gonet "net"
|
||||||
gohttp "net/http"
|
gohttp "net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -1119,6 +1120,12 @@ func (a *api) start() error {
|
|||||||
}(ctx)
|
}(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Debug.MemoryLimit > 0 {
|
||||||
|
debug.SetMemoryLimit(cfg.Debug.MemoryLimit * 1024 * 1024)
|
||||||
|
} else {
|
||||||
|
debug.SetMemoryLimit(math.MaxInt64)
|
||||||
|
}
|
||||||
|
|
||||||
// Start the restream processes
|
// Start the restream processes
|
||||||
restream.Start()
|
restream.Start()
|
||||||
|
|
||||||
|
@@ -232,6 +232,7 @@ func (d *Config) init() {
|
|||||||
// Debug
|
// Debug
|
||||||
d.vars.Register(value.NewBool(&d.Debug.Profiling, false), "debug.profiling", "CORE_DEBUG_PROFILING", nil, "Enable profiling endpoint on /profiling", false, false)
|
d.vars.Register(value.NewBool(&d.Debug.Profiling, false), "debug.profiling", "CORE_DEBUG_PROFILING", nil, "Enable profiling endpoint on /profiling", false, false)
|
||||||
d.vars.Register(value.NewInt(&d.Debug.ForceGC, 0), "debug.force_gc", "CORE_DEBUG_FORCEGC", nil, "Number of seconds between forcing GC to return memory to the OS", false, false)
|
d.vars.Register(value.NewInt(&d.Debug.ForceGC, 0), "debug.force_gc", "CORE_DEBUG_FORCEGC", nil, "Number of seconds between forcing GC to return memory to the OS", false, false)
|
||||||
|
d.vars.Register(value.NewInt64(&d.Debug.MemoryLimit, 0), "debug.memory_limit_mbytes", "CORE_DEBUG_MEMORY_LIMIT_MBYTES", nil, "Impose a soft memory limit for the core, in megabytes", false, false)
|
||||||
|
|
||||||
// Metrics
|
// Metrics
|
||||||
d.vars.Register(value.NewBool(&d.Metrics.Enable, false), "metrics.enable", "CORE_METRICS_ENABLE", nil, "Enable collecting historic metrics data", false, false)
|
d.vars.Register(value.NewBool(&d.Metrics.Enable, false), "metrics.enable", "CORE_METRICS_ENABLE", nil, "Enable collecting historic metrics data", false, false)
|
||||||
|
@@ -135,8 +135,9 @@ type Data struct {
|
|||||||
MaxPort int `json:"max_port"`
|
MaxPort int `json:"max_port"`
|
||||||
} `json:"playout"`
|
} `json:"playout"`
|
||||||
Debug struct {
|
Debug struct {
|
||||||
Profiling bool `json:"profiling"`
|
Profiling bool `json:"profiling"`
|
||||||
ForceGC int `json:"force_gc"`
|
ForceGC int `json:"force_gc"`
|
||||||
|
MemoryLimit int64 `json:"memory_limit_mbytes"`
|
||||||
} `json:"debug"`
|
} `json:"debug"`
|
||||||
Metrics struct {
|
Metrics struct {
|
||||||
Enable bool `json:"enable"`
|
Enable bool `json:"enable"`
|
||||||
@@ -189,7 +190,6 @@ func MergeV2toV3(data *Data, d *v2.Data) (*Data, error) {
|
|||||||
data.SRT = d.SRT
|
data.SRT = d.SRT
|
||||||
data.FFmpeg = d.FFmpeg
|
data.FFmpeg = d.FFmpeg
|
||||||
data.Playout = d.Playout
|
data.Playout = d.Playout
|
||||||
data.Debug = d.Debug
|
|
||||||
data.Metrics = d.Metrics
|
data.Metrics = d.Metrics
|
||||||
data.Sessions = d.Sessions
|
data.Sessions = d.Sessions
|
||||||
data.Service = d.Service
|
data.Service = d.Service
|
||||||
@@ -228,6 +228,10 @@ func MergeV2toV3(data *Data, d *v2.Data) (*Data, error) {
|
|||||||
data.Storage.Memory = d.Storage.Memory
|
data.Storage.Memory = d.Storage.Memory
|
||||||
|
|
||||||
// Actual changes
|
// Actual changes
|
||||||
|
data.Debug.Profiling = d.Debug.Profiling
|
||||||
|
data.Debug.ForceGC = d.Debug.ForceGC
|
||||||
|
data.Debug.MemoryLimit = 0
|
||||||
|
|
||||||
data.TLS.Enable = d.TLS.Enable
|
data.TLS.Enable = d.TLS.Enable
|
||||||
data.TLS.Address = d.TLS.Address
|
data.TLS.Address = d.TLS.Address
|
||||||
data.TLS.Auto = d.TLS.Auto
|
data.TLS.Auto = d.TLS.Auto
|
||||||
@@ -267,7 +271,6 @@ func DowngradeV3toV2(d *Data) (*v2.Data, error) {
|
|||||||
data.SRT = d.SRT
|
data.SRT = d.SRT
|
||||||
data.FFmpeg = d.FFmpeg
|
data.FFmpeg = d.FFmpeg
|
||||||
data.Playout = d.Playout
|
data.Playout = d.Playout
|
||||||
data.Debug = d.Debug
|
|
||||||
data.Metrics = d.Metrics
|
data.Metrics = d.Metrics
|
||||||
data.Sessions = d.Sessions
|
data.Sessions = d.Sessions
|
||||||
data.Service = d.Service
|
data.Service = d.Service
|
||||||
@@ -299,6 +302,9 @@ func DowngradeV3toV2(d *Data) (*v2.Data, error) {
|
|||||||
data.Router.Routes = copy.StringMap(d.Router.Routes)
|
data.Router.Routes = copy.StringMap(d.Router.Routes)
|
||||||
|
|
||||||
// Actual changes
|
// Actual changes
|
||||||
|
data.Debug.Profiling = d.Debug.Profiling
|
||||||
|
data.Debug.ForceGC = d.Debug.ForceGC
|
||||||
|
|
||||||
data.TLS.Enable = d.TLS.Enable
|
data.TLS.Enable = d.TLS.Enable
|
||||||
data.TLS.Address = d.TLS.Address
|
data.TLS.Address = d.TLS.Address
|
||||||
data.TLS.Auto = d.TLS.Auto
|
data.TLS.Auto = d.TLS.Auto
|
||||||
|
Reference in New Issue
Block a user