From 5a929dfeb0839fdf110ed0711d8fd5d5c128ca48 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Sat, 14 Dec 2013 15:20:58 +0200 Subject: [PATCH] some memory profiling and optimization --- cmd/stress/cgr-spansstress/cgr-spansstress.go | 20 ++++++++++--------- engine/calldesc.go | 10 +++------- engine/ratingplan.go | 11 +++++----- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/stress/cgr-spansstress/cgr-spansstress.go b/cmd/stress/cgr-spansstress/cgr-spansstress.go index 461c86c91..f07c4919c 100644 --- a/cmd/stress/cgr-spansstress/cgr-spansstress.go +++ b/cmd/stress/cgr-spansstress/cgr-spansstress.go @@ -48,15 +48,6 @@ func main() { pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } - if *memprofile != "" { - f, err := os.Create(*memprofile) - if err != nil { - log.Fatal(err) - } - pprof.WriteHeapProfile(f) - f.Close() - return - } cd := engine.CallDescriptor{ TimeStart: time.Date(2013, time.December, 13, 22, 30, 0, 0, time.UTC), TimeEnd: time.Date(2013, time.December, 13, 22, 31, 0, 0, time.UTC), @@ -84,7 +75,18 @@ func main() { j := 0 start := time.Now() for i := 0; i < *runs; i++ { + runtime.MemProfileRate = 1 result, err = cd.GetCost() + if *memprofile != "" { + runtime.GC() + f, err := os.Create(*memprofile) + if err != nil { + log.Fatal(err) + } + pprof.WriteHeapProfile(f) + f.Close() + break + } j = i } duration := time.Since(start) diff --git a/engine/calldesc.go b/engine/calldesc.go index f17b4368c..4b0c5cebc 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -266,17 +266,13 @@ func (cd *CallDescriptor) addRatingInfos(ris RatingInfos) bool { return true } -/* -Constructs the key for the storage lookup. -The prefixLen is limiting the length of the destination prefix. -*/ +// Constructs the key for the storage lookup. +// The prefixLen is limiting the length of the destination prefix. func (cd *CallDescriptor) GetKey(subject string) string { return fmt.Sprintf("%s:%s:%s:%s", cd.Direction, cd.Tenant, cd.TOR, subject) } -/* -Splits the received timespan into sub time spans according to the activation periods intervals. -*/ +// Splits the received timespan into sub time spans according to the activation periods intervals. func (cd *CallDescriptor) splitInTimeSpans(firstSpan *TimeSpan) (timespans []*TimeSpan) { if firstSpan == nil { firstSpan = &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cd.TimeEnd, CallDuration: cd.CallDuration} diff --git a/engine/ratingplan.go b/engine/ratingplan.go index 61b2246e4..5db3fc4b7 100644 --- a/engine/ratingplan.go +++ b/engine/ratingplan.go @@ -40,15 +40,16 @@ func (rpr *RPRate) Equal(orpr *RPRate) bool { type RPRateList []*RPRate -func (rp *RatingPlan) RateIntervalList(dId string) (ril RateIntervalList) { - for _, rpr := range rp.DestinationRates[dId] { - ril = append(ril, &RateInterval{ +func (rp *RatingPlan) RateIntervalList(dId string) RateIntervalList { + ril := make(RateIntervalList, len(rp.DestinationRates[dId])) + for i, rpr := range rp.DestinationRates[dId] { + ril[i] = &RateInterval{ Timing: rp.Timings[rpr.Timing], Rating: rp.Ratings[rpr.Rating], Weight: rpr.Weight, - }) + } } - return + return ril } /*