diff --git a/cmd/cgr-tester/simple_max_usage/simple_max_usage.go b/cmd/cgr-tester/simple_max_usage/simple_max_usage.go new file mode 100644 index 000000000..778b50086 --- /dev/null +++ b/cmd/cgr-tester/simple_max_usage/simple_max_usage.go @@ -0,0 +1,145 @@ +/* +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 simple_max_usage.go -requests=10000 -goroutines=5 > + +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: "1001", + 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: "1001", + Account: "1001", + Destination: "1002", + 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/conf/samples/accounts_internal/cgrates.json b/data/conf/samples/accounts_internal/cgrates.json index bd71f7b44..3afb376a7 100644 --- a/data/conf/samples/accounts_internal/cgrates.json +++ b/data/conf/samples/accounts_internal/cgrates.json @@ -27,6 +27,10 @@ }, +"rals": { + "enabled": true, +}, + "accounts": { "enabled": true, diff --git a/data/conf/samples/accounts_mysql/cgrates.json b/data/conf/samples/accounts_mysql/cgrates.json new file mode 100644 index 000000000..7edf29947 --- /dev/null +++ b/data/conf/samples/accounts_mysql/cgrates.json @@ -0,0 +1,54 @@ +{ + +// CGRateS sample configuration file +// Copyright (C) ITsysCOM GmbH +// + + + +"data_db": { + "db_type": "redis", + "db_port": 6379, + "db_name": "10", +}, + + +"stor_db": { + "db_password": "CGRateS.org", +}, + + +"attributes": { + "enabled": true, + +}, + + +"rates": { + "enabled": true, +}, + + +"schedulers": { + "enabled": true, +}, + + +"rals": { + "enabled": true, +}, + + +"accounts": { + "enabled": true, + "attributes_conns": ["*localhost"], + "rates_conns": ["*localhost"], +}, + + +"apiers": { + "enabled": true, +}, + +} + diff --git a/data/tariffplans/oldaccvsnew/AccountActions.csv b/data/tariffplans/oldaccvsnew/AccountActions.csv new file mode 100644 index 000000000..44fa1907f --- /dev/null +++ b/data/tariffplans/oldaccvsnew/AccountActions.csv @@ -0,0 +1,2 @@ +#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled +cgrates.org,1001,AP_PACKAGE_10,,, \ No newline at end of file diff --git a/data/tariffplans/oldaccvsnew/AccountProfiles.csv b/data/tariffplans/oldaccvsnew/AccountProfiles.csv new file mode 100644 index 000000000..347e400b8 --- /dev/null +++ b/data/tariffplans/oldaccvsnew/AccountProfiles.csv @@ -0,0 +1,3 @@ +#Tenant,ID,FilterIDs,ActivationInterval,Weights,Opts,BalanceID,BalanceFilterIDs,BalanceWeights,BalanceType,BalanceUnits,BalanceUnitFactors,BalanceOpts,BalanceCostIncrements,BalanceAttributeIDs,BalanceRateProfileIDs,ThresholdIDs +cgrates.org,1001,*string:~*req.Account:1001,,,,VoiceBalance,,;10,*abstract,3600000000000,,,*string:~*req.ToR:*voice;1000000000;0;0,,, + diff --git a/data/tariffplans/oldaccvsnew/ActionPlans.csv b/data/tariffplans/oldaccvsnew/ActionPlans.csv new file mode 100644 index 000000000..b10e827b5 --- /dev/null +++ b/data/tariffplans/oldaccvsnew/ActionPlans.csv @@ -0,0 +1,2 @@ +#Id,ActionsId,TimingId,Weight +AP_PACKAGE_10,ACT_TOPUP_RST_10,*asap,10 \ No newline at end of file diff --git a/data/tariffplans/oldaccvsnew/Actions.csv b/data/tariffplans/oldaccvsnew/Actions.csv new file mode 100644 index 000000000..f505ed4c2 --- /dev/null +++ b/data/tariffplans/oldaccvsnew/Actions.csv @@ -0,0 +1,2 @@ +#ActionsId[0],Action[1],ExtraParameters[2],Filter[3],BalanceId[4],BalanceType[5],Categories[6],DestinationIds[7],RatingSubject[8],SharedGroup[9],ExpiryTime[10],TimingIds[11],Units[12],BalanceWeight[13],BalanceBlocker[14],BalanceDisabled[15],Weight[16] +ACT_TOPUP_RST_10,*topup_reset,,,test,*voice,,*any,,,*unlimited,,3600000000000,10,false,false,10