-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathclient.py
More file actions
49 lines (40 loc) · 1.55 KB
/
Copy pathclient.py
File metadata and controls
49 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
""" A client which makes requests to the performance testing application. """
import random
import sys
import urllib
# The different operations to perform against the performance application.
# The order matters (do puts before gets and deletes).
OPERATIONS = ["puts", "gets", "queries", "deletes"]
# The number of times operations are done. Results have the average of these.
NUMBER_OF_SAMPLES = 100
def get_random_string():
""" Generates a random string.
Returns:
A str of random characters.
"""
newstr = ""
for _ in range(10):
newstr += str(random.choice('abcdefghijklmnopqrstuvwxyz'))
return newstr
def fetch_operation(server, port, operation, namespace, number):
""" Fetches results of doing puts server side.
Args:
server: A str of the server we are fetching from.
port: An int of the port we are fetching from.
operation: A str of the operation to perform (puts, gets, etc).
namespace: A str of the namespace to perform puts on.
number: An int of the number of the put operations to perform.
Returns:
A str of the result from the server.
"""
data = urllib.urlencode({"namespace": namespace, "number": str(number)})
url = "http://{0}:{1}/{2}".format(server, port, operation)
return urllib.urlopen(url, data).read()
if __name__ == "__main__":
if len(sys.argv) < 3:
print "Example usage: python client.py 192.168.10.33 8080"
exit(1)
for opcode in OPERATIONS:
print "{0}: {1}".format(opcode, fetch_operation(sys.argv[1],
sys.argv[2], opcode, get_random_string(), NUMBER_OF_SAMPLES))
exit(0)