-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·82 lines (63 loc) · 3.14 KB
/
test.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
import memcache
import optparse
import time
def generate_test_payload(size):
return "x" * size
def main():
parser = optparse.OptionParser()
parser.add_option("--host", help="specify the host (default=127.0.0.1)", metavar="HOST",
default="127.0.0.1")
parser.add_option("-p", "--port", help="specify the port (default=2345)", metavar="PORT",
default="2345")
parser.add_option("-s", "--payload-size", help="specify the payload size (default=512)",
metavar="SIZE", default="512")
parser.add_option("-n", "--num-messages", help="specify the number of messages (default=1024)",
metavar="NUM", default="1024")
parser.add_option("-q", "--queue_name", help="specify the name of the queue to use for testing",
metavar="QUEUE_NAME", default="hurley")
parser.add_option("-r", "--read-only", help="perform read tests only. assumes data is already present.", default=False, action="store_true")
parser.add_option("-w", "--write-only", help="perform write tests only.", default=False, action="store_true")
options, args = parser.parse_args()
mc = memcache.Client([':'.join([options.host, options.port])], debug=0)
options.payload_size = int(options.payload_size)
options.num_messages = int(options.num_messages)
test_payload = generate_test_payload(options.payload_size)
total_data_in_mbs = (options.payload_size * options.num_messages) / 1024
if options.read_only and options.write_only:
raise Exception("Cannot enable read_only and write_only at the same time.")
print "Configuration:"
print "Queue name: ", options.queue_name
print "Payload size: ", options.payload_size
print "Number of messages: ", options.num_messages
if options.read_only:
print "(Read only)"
if options.write_only:
print "(Write only)"
print
if not options.read_only:
errors = 0
start = time.time()
for i in range(options.num_messages):
if not mc.set(options.queue_name, test_payload):
errors += 1
end = time.time()
diff = end - start
print "Writing %d messages of size %d took %0.3f seconds - %0.3f msg/s - %0.3f MB/s (with %d errors)" % (options.num_messages, options.payload_size, diff, (options.num_messages/diff), (total_data_in_mbs/diff/1024), errors)
if not options.write_only:
responses = []
start = time.time()
for i in range(options.num_messages):
responses.append(mc.get(options.queue_name))
end = time.time()
diff = end - start
print "Reading %d messages took %0.3f seconds - %0.3f m/s - %0.3f MB/s" % (options.num_messages, diff, (options.num_messages/diff), (total_data_in_mbs/diff/1024))
if not (options.read_only or options.write_only):
print "Checking response correctness."
errors = 0
for response in responses:
if response != test_payload:
errors += 1
print "Found %d errors in %d responses." % (errors, len(responses))
if __name__ == "__main__":
main()