Example #1
0
func (smg *SMGeneric) LCRSuppliers(gev SMGenericEvent) (suppls []string, err error) {
	cacheKey := "LCRSuppliers" + gev.GetCgrId(smg.timezone) + gev.GetAccount(utils.META_DEFAULT) + gev.GetDestination(utils.META_DEFAULT)
	if item, err := smg.responseCache.Get(cacheKey); err == nil && item != nil {
		if item.Value != nil {
			suppls = (item.Value.([]string))
		}
		err = item.Err
		return suppls, err
	}
	defer smg.responseCache.Cache(cacheKey, &cache.CacheItem{Value: suppls, Err: err})
	gev[utils.EVENT_NAME] = utils.CGR_LCR_REQUEST
	var cd *engine.CallDescriptor
	cd, err = gev.AsLcrRequest().AsCallDescriptor(smg.timezone)
	cd.CgrID = gev.GetCgrId(smg.timezone)
	if err != nil {
		return
	}
	var lcr engine.LCRCost
	if err = smg.rater.Call("Responder.GetLCR", &engine.AttrGetLcr{CallDescriptor: cd}, &lcr); err != nil {
		return
	}
	if lcr.HasErrors() {
		lcr.LogErrors()
		err = errors.New("LCR_COMPUTE_ERROR")
		return
	}
	suppls, err = lcr.SuppliersSlice()
	return
}
Example #2
0
func durInternalRater(cd *engine.CallDescriptor) (time.Duration, error) {
	ratingDb, err := engine.ConfigureRatingStorage(*ratingdb_type, *ratingdb_host, *ratingdb_port, *ratingdb_name, *ratingdb_user, *ratingdb_pass, *dbdata_encoding, *cacheDumpDir, *loadHistorySize)
	if err != nil {
		return nilDuration, fmt.Errorf("Could not connect to rating database: %s", err.Error())
	}
	defer ratingDb.Close()
	engine.SetRatingStorage(ratingDb)
	accountDb, err := engine.ConfigureAccountingStorage(*accountdb_type, *accountdb_host, *accountdb_port, *accountdb_name, *accountdb_user, *accountdb_pass, *dbdata_encoding, *cacheDumpDir, *loadHistorySize)
	if err != nil {
		return nilDuration, fmt.Errorf("Could not connect to accounting database: %s", err.Error())
	}
	defer accountDb.Close()
	engine.SetAccountingStorage(accountDb)
	if err := ratingDb.CacheRatingAll("cgr-tester"); err != nil {
		return nilDuration, fmt.Errorf("Cache rating error: %s", err.Error())
	}
	if err := accountDb.CacheAccountingAll("cgr-tester"); err != nil {
		return nilDuration, fmt.Errorf("Cache accounting error: %s", err.Error())
	}
	log.Printf("Runnning %d cycles...", *runs)
	var result *engine.CallCost
	j := 0
	start := time.Now()
	for i := 0; i < *runs; i++ {
		result, err = cd.GetCost()
		if *memprofile != "" {
			runtime.MemProfileRate = 1
			runtime.GC()
			f, err := os.Create(*memprofile)
			if err != nil {
				log.Fatal(err)
			}
			pprof.WriteHeapProfile(f)
			f.Close()
			break
		}
		j = i
	}
	log.Print(result, j, err)
	memstats := new(runtime.MemStats)
	runtime.ReadMemStats(memstats)
	log.Printf("memstats before GC: Kbytes = %d footprint = %d",
		memstats.HeapAlloc/1024, memstats.Sys/1024)
	return time.Since(start), nil
}