mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
better cpu detection
This commit is contained in:
9
README
9
README
@@ -1 +1,8 @@
|
||||
Rating system for telecom providers.
|
||||
Rating system for telecom providers.
|
||||
|
||||
Match datetime objects instead of timestamp. Example
|
||||
Year \d{4} #any year
|
||||
Month \d{2} #any month
|
||||
Day \d{2} # any day
|
||||
Hour (0[89]|1\d) #from 08 till 19
|
||||
Minute \d{2}
|
||||
|
||||
@@ -13,15 +13,15 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const NCPU = 4
|
||||
|
||||
var (
|
||||
nCPU = runtime.NumCPU()
|
||||
raterList *RaterList
|
||||
inChannels [NCPU]chan string
|
||||
outChannels [NCPU]chan string
|
||||
inChannels []chan string
|
||||
outChannels []chan string
|
||||
multiplexerIndex int
|
||||
mu sync.Mutex
|
||||
sem = make(chan int, NCPU)
|
||||
sem = make(chan int, nCPU)
|
||||
)
|
||||
|
||||
|
||||
@@ -43,9 +43,10 @@ Creates a gorutine for every cpu core and the multiplexses the calls to each of
|
||||
*/
|
||||
func initThreadedCallRater(){
|
||||
multiplexerIndex = 0
|
||||
runtime.GOMAXPROCS(NCPU)
|
||||
fmt.Println(runtime.GOMAXPROCS(NCPU))
|
||||
for i:= 0; i< NCPU; i++ {
|
||||
runtime.GOMAXPROCS(nCPU)
|
||||
inChannels = make([]chan string, nCPU)
|
||||
outChannels = make([]chan string, nCPU)
|
||||
for i:= 0; i< nCPU; i++ {
|
||||
inChannels[i] = make(chan string)
|
||||
outChannels[i] = make(chan string)
|
||||
go func(in, out chan string){
|
||||
@@ -62,7 +63,7 @@ func initThreadedCallRater(){
|
||||
func ThreadedCallRater(key string) (replay string) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if multiplexerIndex >= NCPU {
|
||||
if multiplexerIndex >= nCPU {
|
||||
multiplexerIndex = 0
|
||||
}
|
||||
inChannels[multiplexerIndex] <- key
|
||||
|
||||
@@ -4,31 +4,61 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type BilingUnit int
|
||||
|
||||
type RatingProfile struct {
|
||||
StartTime time.Time
|
||||
ConnectFee float32
|
||||
Price float32
|
||||
BillingUnit BilingUnit
|
||||
StartTime time.Duration
|
||||
ConnectFee, Price, BillingUnit float32
|
||||
}
|
||||
|
||||
type ActivationPeriod struct {
|
||||
ActivationTime time.Time
|
||||
RatingProfiles []RatingProfile
|
||||
RatingProfiles []*RatingProfile
|
||||
}
|
||||
|
||||
func (cd *ActivationPeriod) SplitInTimeSpans(t []*ActivationPeriods) (timespans []*TimeSpans) {
|
||||
for i, ap := range aps {
|
||||
t := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cdTimeEnd}
|
||||
timespans = append(timespans, aps.SplitInTimeSlots(t))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *ActivationPeriod) AddRatingProfile(rp ...*RatingProfile) {
|
||||
for _, r := range rp {
|
||||
c.RatingProfiles = append(c.RatingProfiles, r)
|
||||
}
|
||||
}
|
||||
|
||||
type Customer struct {
|
||||
Id string
|
||||
Prefix string
|
||||
ActivationPeriods []ActivationPeriod
|
||||
CstmId string
|
||||
DestinationPrefix string
|
||||
ActivationPeriods []*ActivationPeriod
|
||||
}
|
||||
|
||||
func (c *Customer) AddActivationPeriod(ap ...*ActivationPeriod) {
|
||||
for _,a := range ap {
|
||||
c.ActivationPeriods = append(c.ActivationPeriods, a)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Customer) SplitInTimeSpans(cd *CallDescription) (timespans []*TimeSpans) {
|
||||
t := &TimeSpan{TimeStart: cd.TimeStart, TimeEnd: cdTimeEnd}
|
||||
for i, ap := range c.ActivationPeriods {
|
||||
timespans = append(timespans, aps.SplitInTimeSlots(t))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Customer) CleanOldActivationPeriods() {
|
||||
now := time.Now()
|
||||
obsoleteIndex := -1
|
||||
for i, ap := range c.ActivationPeriods {
|
||||
if i > len(c.ActivationPeriods) - 2 {
|
||||
break
|
||||
}
|
||||
if a
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
SECONDS =iota
|
||||
COUNT
|
||||
BYTES
|
||||
)
|
||||
|
||||
type CallDescription struct {
|
||||
TOR int
|
||||
@@ -36,6 +66,12 @@ type CallDescription struct {
|
||||
TimeStart, TimeEnd time.Time
|
||||
}
|
||||
|
||||
type TimeSpan struct {
|
||||
TimeStart, TimeEnd time.Time
|
||||
RatingProfile *RatingProfile
|
||||
}
|
||||
|
||||
|
||||
type CallCost struct {
|
||||
TOR int
|
||||
CstmId, Subject, Prefix string
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
package timeslots
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func setUp() {
|
||||
c1 := &Customer{CstmId:"rif",DestinationPrefix: "40256"}
|
||||
t1 := time.Date(2012, time.January, 10, 23, 0, 0, 0, time.UTC)
|
||||
ap1 := &ActivationPeriod{ActivationTime: t1}
|
||||
c1.AddActivationPeriod(ap1)
|
||||
d1,_ := time.ParseDuration("1m")
|
||||
d2,_ := time.ParseDuration("2m")
|
||||
r1 := &RatingProfile{StartTime: d1, ConnectFee: 1.1, Price: 0.1, BillingUnit: SECOND}
|
||||
r2 := &RatingProfile{StartTime: d2, ConnectFee: 2.2, Price: 0.2, BillingUnit: SECOND}
|
||||
ap1.AddRatingProfile(r1, r2)
|
||||
}
|
||||
|
||||
func TestSimple(t *testing.T){
|
||||
setUp()
|
||||
cc, err := GetCost(nil, nil)
|
||||
if err != nil {
|
||||
t.Error("Got error on getting cost")
|
||||
|
||||
Reference in New Issue
Block a user