Skip to content

Commit 91ee022

Browse files
committed
extra utilities for load testing
1 parent a238e78 commit 91ee022

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
import sys, getopt, argparse
3+
import logging
4+
from random import randint,random,uniform
5+
import json
6+
import urllib
7+
8+
PREDICT_TEMPLATE = 'http://seldon-server/js/predict?json=%JSON%&consumer_key=%KEY%&jsonpCallback=j'
9+
10+
class ReplayCreate(object):
11+
12+
def __init__(self):
13+
self.features = []
14+
15+
def get_key(self,filename):
16+
with open(filename) as f:
17+
for line in f:
18+
line = line.rstrip()
19+
j = json.loads(line)
20+
self.key = j[0]["key"]
21+
22+
def parse_features(self,features):
23+
for f in features:
24+
j = json.loads(f)
25+
self.features.append(j)
26+
27+
def construct_json(self):
28+
j = {}
29+
for f in self.features:
30+
31+
if f["type"] == "numeric":
32+
fval = uniform(f["min"],f["max"])
33+
j[f["name"]] = fval
34+
return json.dumps(j)
35+
36+
def create_replay(self,filename,num):
37+
with open(filename,"w") as f:
38+
for i in range (0,num):
39+
jStr = self.construct_json()
40+
jEncoded = urllib.quote_plus(jStr)
41+
url = PREDICT_TEMPLATE.replace("%KEY%",self.key).replace("%JSON%",jEncoded)+"\n"
42+
f.write(url)
43+
44+
if __name__ == '__main__':
45+
import logging
46+
logger = logging.getLogger()
47+
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(name)s : %(message)s', level=logging.DEBUG)
48+
logger.setLevel(logging.INFO)
49+
50+
parser = argparse.ArgumentParser(prog='create_replay')
51+
parser.add_argument('--key', help='file containing output of seldon-cli keys call', required=True)
52+
parser.add_argument('--replay', help='replay file to create', required=True)
53+
parser.add_argument('--num', help='number of actions and recommendation pair calls to create', required=False, type=int, default=1000)
54+
parser.add_argument('--feature', help='feature to add ', required=True, action='append')
55+
56+
args = parser.parse_args()
57+
opts = vars(args)
58+
59+
rc = ReplayCreate()
60+
rc.get_key(args.key)
61+
rc.parse_features(args.feature)
62+
rc.create_replay(args.replay,args.num)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -o nounset
4+
set -o errexit
5+
6+
if [ "$#" -ne 2 ]; then
7+
echo "need <client name> <file>"
8+
exit -1
9+
fi
10+
11+
CLIENT=$1
12+
FILE=$2
13+
14+
seldon-cli -q keys --client-name ${CLIENT} --scope js > key.json
15+
python create_prediction_replay.py --key key.json --replay ${FILE} --feature '{"name":"f1","type":"numeric","min":0,"max":5}' --feature '{"name":"f2","type":"numeric","min":0,"max":5}' --feature '{"name":"f3","type":"numeric","min":0,"max":5}' --feature '{"name":"f4","type":"numeric","min":0,"max":5}'

0 commit comments

Comments
 (0)