diff --git a/cmd/cgr-tester/combined_max_usage/combined_max_usage.go b/cmd/cgr-tester/combined_max_usage/combined_max_usage.go index ae21fb688..d01925b97 100644 --- a/cmd/cgr-tester/combined_max_usage/combined_max_usage.go +++ b/cmd/cgr-tester/combined_max_usage/combined_max_usage.go @@ -45,6 +45,9 @@ var ( // 1) Start the engine with the following configuration < cgr-engine -config_path=/usr/share/cgrates/conf/samples/accounts_mysql > // 2) Load the data with < cgr-loader -config_path=/usr/share/cgrates/conf/samples/accounts_mysql -verbose -path=/usr/share/cgrates/tariffplans/oldaccvsnew > // 3) Run the program with < go run combined_max_usage.go -requests=10000 -goroutines=5 > +// Additional Information +// In this scenario we compare the old account system vs the new one. The balance contains the RateID in order to access it directly without the needed of matching. +// For this scenario the account 1002 is used func main() { flag.Parse() diff --git a/cmd/cgr-tester/combined_max_usage2/combined_max_usage2.go b/cmd/cgr-tester/combined_max_usage2/combined_max_usage2.go new file mode 100644 index 000000000..69ef57281 --- /dev/null +++ b/cmd/cgr-tester/combined_max_usage2/combined_max_usage2.go @@ -0,0 +1,148 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +package main + +import ( + "flag" + "fmt" + "log" + "math/rand" + "net/rpc" + "net/rpc/jsonrpc" + "path" + "sync" + "time" + + "github.com/cgrates/cgrates/engine" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/utils" +) + +var ( + dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") + requests = flag.Int("requests", 10000, "Number of requests") + gorutines = flag.Int("goroutines", 5, "Number of simultaneous goroutines") +) + +// How to run: +// 1) Start the engine with the following configuration < cgr-engine -config_path=/usr/share/cgrates/conf/samples/accounts_mysql > +// 2) Load the data with < cgr-loader -config_path=/usr/share/cgrates/conf/samples/accounts_mysql -verbose -path=/usr/share/cgrates/tariffplans/oldaccvsnew > +// 3) Run the program with < go run combined_max_usage2.go -requests=10000 -goroutines=5 > +// Additional Information +// In this scenario we compare the old account system vs the new one. The balance doesn't contains the RateID and will let RateS to discover the rate profile that match the event. +// For this scenario the account 1003 is used + +func main() { + flag.Parse() + var err error + var rpc *rpc.Client + var cfgPath string + var cfg *config.CGRConfig + cfgPath = path.Join(*dataDir, "conf", "samples", "accounts_mysql") + if cfg, err = config.NewCGRConfigFromPath(cfgPath); err != nil { + log.Fatal("Got config error: ", err.Error()) + } + if rpc, err = jsonrpc.Dial(utils.TCP, cfg.ListenCfg().RPCJSONListen); err != nil { + return + } + + s1 := rand.NewSource(time.Now().UnixNano()) + r1 := rand.New(s1) + + var wgAccountS sync.WaitGroup + var accountSTime time.Duration + var sumAccountS float64 + + var wgRALs sync.WaitGroup + var ralsTime time.Duration + var sumRALs float64 + + for i := 0; i < *requests; i++ { + wgAccountS.Add(1) + wgRALs.Add(1) + usage := fmt.Sprintf("%+vm", 1+r1.Intn(59)) + go func() { + var eEc *utils.ExtEventCharges + arg := &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: utils.UUIDSha1Prefix(), + Event: map[string]interface{}{ + utils.AccountField: "1003", + utils.ToR: utils.MetaVoice, + utils.Usage: usage, + }}} + tNow := time.Now() + if err := rpc.Call(utils.AccountSv1MaxUsage, + arg, &eEc); err != nil { + return + } + accountSTime += time.Now().Sub(tNow) + sumAccountS += *eEc.Usage + wgAccountS.Done() + }() + + go func() { + tStart := time.Date(2016, 3, 31, 0, 0, 0, 0, time.UTC) + usageDur, _ := utils.ParseDurationWithNanosecs(usage) + cd := &engine.CallDescriptorWithOpts{ + CallDescriptor: &engine.CallDescriptor{ + Category: "call", + Tenant: "cgrates.org", + Subject: "1003", + Account: "1003", + Destination: "1004", + TimeStart: tStart, + TimeEnd: tStart.Add(usageDur), + }, + } + var rply time.Duration + tNow := time.Now() + if err := rpc.Call(utils.ResponderGetMaxSessionTime, cd, &rply); err != nil { + return + } + ralsTime += time.Now().Sub(tNow) + sumRALs += rply.Seconds() + wgRALs.Done() + }() + + if i%*gorutines == 0 { + wgAccountS.Wait() + wgRALs.Wait() + } + + } + wgAccountS.Wait() + wgRALs.Wait() + + fmt.Println("Sum AccountS MaxUsage") + fmt.Println(sumAccountS) + fmt.Println("Average AccountS MaxUsage") + fmt.Println(accountSTime / time.Duration(*requests)) + fmt.Println("Total AccountS MaxUsage Time") + fmt.Println(accountSTime) + + fmt.Println("Sum RALs GetMaxSessionTime") + fmt.Println(sumRALs) + fmt.Println("Average RALs GetMaxSessionTime") + fmt.Println(ralsTime / time.Duration(*requests)) + fmt.Println("Total RALs GetMaxSessionTime Time") + fmt.Println(ralsTime) + +} diff --git a/data/tariffplans/oldaccvsnew/AccountActions.csv b/data/tariffplans/oldaccvsnew/AccountActions.csv index d4eaddc97..38d1be927 100644 --- a/data/tariffplans/oldaccvsnew/AccountActions.csv +++ b/data/tariffplans/oldaccvsnew/AccountActions.csv @@ -1,3 +1,4 @@ #Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled cgrates.org,1001,AP_PACKAGE_10,,, -cgrates.org,1002,AP_PACKAGE_11,,, \ No newline at end of file +cgrates.org,1002,AP_PACKAGE_11,,, +cgrates.org,1003,AP_PACKAGE_11,,, \ No newline at end of file diff --git a/data/tariffplans/oldaccvsnew/AccountProfiles.csv b/data/tariffplans/oldaccvsnew/AccountProfiles.csv index 3ee58b813..10c7efa30 100644 --- a/data/tariffplans/oldaccvsnew/AccountProfiles.csv +++ b/data/tariffplans/oldaccvsnew/AccountProfiles.csv @@ -2,3 +2,5 @@ cgrates.org,1001,*string:~*req.Account:1001,,,,VoiceBalance,,;10,*abstract,3600000000000,,,*string:~*req.ToR:*voice;1000000000;0;0,,, cgrates.org,1002,*string:~*req.Account:1002,,,,VoiceBalance,,;10,*abstract,3600000000000,,,*string:~*req.ToR:*voice;1000000000;;,,RP_ANY, cgrates.org,1002,,,,,MonetaryBalance,,;10,*concrete,100,,,,,, +cgrates.org,1003,*string:~*req.Account:1003,,,,VoiceBalance,,;10,*abstract,3600000000000,,,*string:~*req.ToR:*voice;1000000000;;,,, +cgrates.org,1003,,,,,MonetaryBalance,,;10,*concrete,100,,,,,,