mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Revise memory profiling implementation
- merge StopChanMemProf with StopMemoryProfiling - remove fileMEM and stopMemProf from struct and constructors - add separate mutex for memory profiling, ensure thread safety - handle all significant errors - log error if StopMemoryProfiling fails during CoreS Shutdown - ignore errors if profiling inactive in Shutdown and deferred Stop - move validations inside V1 functions - return error if StartMemoryProfiling already started - return error if StopMemoryProfiling already stopped or never started - close profiling loop on error, not the cgr-engine - StopMemoryProfiling closes channel and profiling loop writes final profile - rename Path to DirPath for mandatory field error - rename memprof_nrfiles flag to memprof_maxfiles - increase default memprof_interval - consider MaxFiles <= 0 as unlimited - move memory profiling logic after starting services - use CoreService Start/StopMemoryProfiling in main - remove final memory profile block (created by deferred Stop) - convert MemProfiling to method on CoreService and rename to profileMemory - use Ticker for recurrent actions instead of Timer - compute mem_final.prof full path in StartMemoryProfiling - suffix profile files with current time instead of numbers - update dispatcher methods after changes - move MemoryPrf from utils to cores, rename to MemoryProfilingParams - add logs for starting/stopping profiling
This commit is contained in:
committed by
Dan Christian Bogos
parent
9d4561f79c
commit
1c490a9020
@@ -33,39 +33,35 @@ import (
|
||||
// NewCoreService returns the Core Service
|
||||
func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, server *cores.Server,
|
||||
internalCoreSChan chan birpc.ClientConnector, anz *AnalyzerService,
|
||||
fileCpu io.Closer, fileMEM string, shdWg *sync.WaitGroup, stopMemPrf chan struct{},
|
||||
shdChan *utils.SyncedChan, srvDep map[string]*sync.WaitGroup) *CoreService {
|
||||
fileCpu io.Closer, shdWg *sync.WaitGroup, shdChan *utils.SyncedChan,
|
||||
srvDep map[string]*sync.WaitGroup) *CoreService {
|
||||
return &CoreService{
|
||||
shdChan: shdChan,
|
||||
shdWg: shdWg,
|
||||
stopMemPrf: stopMemPrf,
|
||||
connChan: internalCoreSChan,
|
||||
cfg: cfg,
|
||||
caps: caps,
|
||||
fileCpu: fileCpu,
|
||||
fileMem: fileMEM,
|
||||
server: server,
|
||||
anz: anz,
|
||||
srvDep: srvDep,
|
||||
shdChan: shdChan,
|
||||
shdWg: shdWg,
|
||||
connChan: internalCoreSChan,
|
||||
cfg: cfg,
|
||||
caps: caps,
|
||||
fileCpu: fileCpu,
|
||||
server: server,
|
||||
anz: anz,
|
||||
srvDep: srvDep,
|
||||
}
|
||||
}
|
||||
|
||||
// CoreService implements Service interface
|
||||
type CoreService struct {
|
||||
sync.RWMutex
|
||||
cfg *config.CGRConfig
|
||||
server *cores.Server
|
||||
caps *engine.Caps
|
||||
stopChan chan struct{}
|
||||
shdWg *sync.WaitGroup
|
||||
stopMemPrf chan struct{}
|
||||
shdChan *utils.SyncedChan
|
||||
fileCpu io.Closer
|
||||
fileMem string
|
||||
cS *cores.CoreService
|
||||
connChan chan birpc.ClientConnector
|
||||
anz *AnalyzerService
|
||||
srvDep map[string]*sync.WaitGroup
|
||||
cfg *config.CGRConfig
|
||||
server *cores.Server
|
||||
caps *engine.Caps
|
||||
stopChan chan struct{}
|
||||
shdWg *sync.WaitGroup
|
||||
shdChan *utils.SyncedChan
|
||||
fileCpu io.Closer
|
||||
cS *cores.CoreService
|
||||
connChan chan birpc.ClientConnector
|
||||
anz *AnalyzerService
|
||||
srvDep map[string]*sync.WaitGroup
|
||||
}
|
||||
|
||||
// Start should handle the service start
|
||||
@@ -78,7 +74,7 @@ func (cS *CoreService) Start() error {
|
||||
defer cS.Unlock()
|
||||
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.CoreS))
|
||||
cS.stopChan = make(chan struct{})
|
||||
cS.cS = cores.NewCoreService(cS.cfg, cS.caps, cS.fileCpu, cS.fileMem, cS.stopChan, cS.shdWg, cS.stopMemPrf, cS.shdChan)
|
||||
cS.cS = cores.NewCoreService(cS.cfg, cS.caps, cS.fileCpu, cS.stopChan, cS.shdWg, cS.shdChan)
|
||||
srv, err := engine.NewServiceWithName(cS.cS, utils.CoreS, true)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestCoreSReload(t *testing.T) {
|
||||
coreRPC := make(chan birpc.ClientConnector, 1)
|
||||
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep)
|
||||
caps := engine.NewCaps(1, "test_caps")
|
||||
coreS := NewCoreService(cfg, caps, server, coreRPC, anz, nil, "", nil, nil, nil, srvDep)
|
||||
coreS := NewCoreService(cfg, caps, server, coreRPC, anz, nil, nil, nil, srvDep)
|
||||
engine.NewConnManager(cfg, nil)
|
||||
srvMngr.AddServices(coreS,
|
||||
NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db)
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestCoreSCoverage(t *testing.T) {
|
||||
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
|
||||
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep)
|
||||
srv := NewCoreService(cfg, caps, server,
|
||||
internalCoreSChan, anz, nil, "/tmp", nil, nil, nil, srvDep)
|
||||
internalCoreSChan, anz, nil, nil, nil, srvDep)
|
||||
if srv == nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(srv))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user