mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 00:17:07 +08:00
Fix debug.force_gc behaviour
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
|||||||
gohttp "net/http"
|
gohttp "net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -1271,11 +1270,10 @@ func (a *api) start() error {
|
|||||||
// Wait for all servers to be started
|
// Wait for all servers to be started
|
||||||
wgStart.Wait()
|
wgStart.Wait()
|
||||||
|
|
||||||
|
if cfg.Debug.ForceGC > 0 {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
a.gcTickerStop = cancel
|
a.gcTickerStop = cancel
|
||||||
|
|
||||||
if cfg.Debug.ForceGC > 0 {
|
|
||||||
/*
|
|
||||||
go func(ctx context.Context) {
|
go func(ctx context.Context) {
|
||||||
ticker := time.NewTicker(time.Duration(cfg.Debug.ForceGC) * time.Second)
|
ticker := time.NewTicker(time.Duration(cfg.Debug.ForceGC) * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
@@ -1285,21 +1283,18 @@ func (a *api) start() error {
|
|||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
debug.FreeOSMemory()
|
debug.FreeOSMemory()
|
||||||
}
|
/*
|
||||||
}
|
|
||||||
}(ctx)
|
|
||||||
*/
|
|
||||||
go func(ctx context.Context) {
|
|
||||||
ticker := time.NewTicker(time.Duration(cfg.Debug.ForceGC) * time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
var mem runtime.MemStats
|
var mem runtime.MemStats
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
runtime.ReadMemStats(&mem)
|
runtime.ReadMemStats(&mem)
|
||||||
fmt.Printf("mem in use: %.02f MiB\n", float64(mem.HeapInuse)/(1<<20))
|
a.log.logger.main.WithComponent("memory").Debug().WithFields(log.Fields{
|
||||||
|
"Sys": float64(mem.Sys) / (1 << 20),
|
||||||
|
"HeapSys": float64(mem.HeapSys) / (1 << 20),
|
||||||
|
"HeapAlloc": float64(mem.HeapAlloc) / (1 << 20),
|
||||||
|
"HeapIdle": float64(mem.HeapIdle) / (1 << 20),
|
||||||
|
"HeapInuse": float64(mem.HeapInuse) / (1 << 20),
|
||||||
|
"HeapReleased": float64(mem.HeapReleased) / (1 << 20),
|
||||||
|
}).Log("")
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(ctx)
|
}(ctx)
|
||||||
|
Reference in New Issue
Block a user