mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
code cleanups
This commit is contained in:
@@ -10,19 +10,10 @@ import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
nCPU = runtime.NumCPU()
|
||||
raterList *RaterList
|
||||
inChannels []chan *timespans.CallDescriptor
|
||||
outChannels []chan *timespans.CallCost
|
||||
multiplexerIndex int
|
||||
mu sync.Mutex
|
||||
sem = make(chan int, nCPU)
|
||||
)
|
||||
var raterList *RaterList
|
||||
|
||||
/*
|
||||
Handler for the statistics web client
|
||||
@@ -36,40 +27,6 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "</ol></body></html>")
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a gorutine for every cpu core and the multiplexses the calls to each of them.
|
||||
*/
|
||||
func initThreadedCallRater() {
|
||||
multiplexerIndex = 0
|
||||
runtime.GOMAXPROCS(nCPU)
|
||||
inChannels = make([]chan *timespans.CallDescriptor, nCPU)
|
||||
outChannels = make([]chan *timespans.CallCost, nCPU)
|
||||
for i := 0; i < nCPU; i++ {
|
||||
inChannels[i] = make(chan *timespans.CallDescriptor)
|
||||
outChannels[i] = make(chan *timespans.CallCost)
|
||||
go func(in chan *timespans.CallDescriptor, out chan *timespans.CallCost) {
|
||||
for {
|
||||
key := <-in
|
||||
out <- CallRater(key)
|
||||
}
|
||||
}(inChannels[i], outChannels[i])
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
func ThreadedCallRater(key *timespans.CallDescriptor) (reply *timespans.CallCost) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if multiplexerIndex >= nCPU {
|
||||
multiplexerIndex = 0
|
||||
}
|
||||
inChannels[multiplexerIndex] <- key
|
||||
reply = <-outChannels[multiplexerIndex]
|
||||
multiplexerIndex++
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
The function that gets the information from the raters using balancer.
|
||||
*/
|
||||
@@ -124,7 +81,7 @@ func main() {
|
||||
|
||||
go StopSingnalHandler()
|
||||
go listenToTheWorld()
|
||||
//initThreadedCallRater()
|
||||
runtime.GOMAXPROCS(runtime.NumCPU() - 1)
|
||||
http.HandleFunc("/", handler)
|
||||
log.Print("The server is listening...")
|
||||
http.ListenAndServe(":2000", nil)
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
runs = flag.Int("runs", 10000, "stress cycle number")
|
||||
parallel = flag.Bool("parallel", false, "run requests in parallel")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := timespans.CallCost{}
|
||||
client, _ := jsonrpc.Dial("tcp", "localhost:5090")
|
||||
runs := int(1e5)
|
||||
i := 0
|
||||
c := make(chan string)
|
||||
for ; i < runs; i++ {
|
||||
go func() {
|
||||
var reply string
|
||||
if *parallel {
|
||||
c := make(chan string)
|
||||
for ; i < *runs; i++ {
|
||||
go func() {
|
||||
var reply string
|
||||
client.Call("Responder.Get", cd, &result)
|
||||
c <- reply
|
||||
}()
|
||||
//time.Sleep(1*time.Second)
|
||||
}
|
||||
for j := 0; j < *runs; j++ {
|
||||
<-c
|
||||
}
|
||||
} else {
|
||||
for j := 0; j < *runs; j++ {
|
||||
client.Call("Responder.Get", cd, &result)
|
||||
c <- reply
|
||||
}()
|
||||
//time.Sleep(1*time.Second)
|
||||
}
|
||||
for j := 0; j < runs; j++ {
|
||||
<-c
|
||||
}
|
||||
}
|
||||
log.Println(result)
|
||||
log.Println(i)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"time"
|
||||
"flag"
|
||||
)
|
||||
|
||||
var (
|
||||
runs = flag.Int("runs", 10000, "stress cycle number")
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := timespans.CallCost{}
|
||||
client, _ := jsonrpc.Dial("tcp", "localhost:5090")
|
||||
i := 0
|
||||
for j := 0; j < *runs; j++ {
|
||||
client.Call("Storage.GetCost", cd, &result)
|
||||
}
|
||||
log.Println(result)
|
||||
log.Println(i)
|
||||
client.Close()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
var (
|
||||
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
runs = flag.Int("runs", 10000, "stress cycle number")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@@ -27,15 +30,18 @@ func main() {
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{CstmId: "vdf", Subject: "rif", DestinationPrefix: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
|
||||
i := 0
|
||||
result := ×pans.CallCost{}
|
||||
var result *timespans.CallCost
|
||||
|
||||
getter, _ := timespans.NewRedisStorage("", 10)
|
||||
defer getter.Close()
|
||||
|
||||
i := 0
|
||||
log.Printf("Runnning %d cycles...", *runs)
|
||||
|
||||
for ; i < 1e5; i++ {
|
||||
for j := 0; j < *runs; j++ {
|
||||
result, _ = cd.GetCost(getter)
|
||||
}
|
||||
|
||||
log.Print(result)
|
||||
log.Print(i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user