mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
moved stress tools
This commit is contained in:
33
cmd/stress/inquirerstress/stresstest.go
Normal file
33
cmd/stress/inquirerstress/stresstest.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc/jsonrpc"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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
|
||||
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)
|
||||
client.Close()
|
||||
}
|
||||
57
cmd/stress/inquirerstress/stresstest.py
Normal file
57
cmd/stress/inquirerstress/stresstest.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# jsonclient.py
|
||||
# A simple JSONRPC client library, created to work with Go servers
|
||||
# Written by Stephen Day
|
||||
# Modified by Bruce Eckel to work with both Python 2 & 3
|
||||
import json, socket, itertools
|
||||
from datetime import datetime
|
||||
|
||||
class JSONClient(object):
|
||||
|
||||
def __init__(self, addr, codec=json):
|
||||
self._socket = socket.create_connection(addr)
|
||||
self._id_iter = itertools.count()
|
||||
self._codec = codec
|
||||
|
||||
def _message(self, name, *params):
|
||||
return dict(id=next(self._id_iter),
|
||||
params=list(params),
|
||||
method=name)
|
||||
|
||||
def call(self, name, *params):
|
||||
request = self._message(name, *params)
|
||||
id = request.get('id')
|
||||
msg = self._codec.dumps(request)
|
||||
self._socket.sendall(msg.encode())
|
||||
|
||||
# This will actually have to loop if resp is bigger
|
||||
response = self._socket.recv(4096)
|
||||
response = self._codec.loads(response.decode())
|
||||
|
||||
if response.get('id') != id:
|
||||
raise Exception("expected id=%s, received id=%s: %s"
|
||||
%(id, response.get('id'),
|
||||
response.get('error')))
|
||||
|
||||
if response.get('error') is not None:
|
||||
raise Exception(response.get('error'))
|
||||
|
||||
return response.get('result')
|
||||
|
||||
def close(self):
|
||||
self._socket.close()
|
||||
|
||||
|
||||
rpc =JSONClient(("127.0.0.1", 5090))
|
||||
|
||||
cd = {"Tor":0, "CstmId": "vdf", "Subject": "rif", "DestinationPrefix": "0256", "TimeStart": "2012-02-02T17:30:00Z", "TimeEnd": "2012-02-02T18:30:00Z"}
|
||||
|
||||
# alternative to the above
|
||||
s = socket.create_connection(("127.0.0.1", 5090))
|
||||
s.sendall(json.dumps(({"id": 1, "method": "Responder.Get", "params": [cd]})))
|
||||
print s.recv(4096)
|
||||
|
||||
i = 0
|
||||
result = ""
|
||||
for i in xrange(int(1e5) + 1):
|
||||
result = rpc.call("Responder.Get", cd)
|
||||
print i, result
|
||||
41
cmd/stress/spansstress/tsstress.go
Normal file
41
cmd/stress/spansstress/tsstress.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/rif/cgrates/timespans"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"time"
|
||||
)
|
||||
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *cpuprofile != "" {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
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}
|
||||
|
||||
i := 0
|
||||
result := ×pans.CallCost{}
|
||||
|
||||
getter, _ := timespans.NewRedisStorage("", 10)
|
||||
defer getter.Close()
|
||||
|
||||
for ; i < 1e5; i++ {
|
||||
result, _ = cd.GetCost(getter)
|
||||
}
|
||||
log.Print(result)
|
||||
log.Print(i)
|
||||
}
|
||||
Reference in New Issue
Block a user