1#this script will run until stopped. it will set keys with small/large values
2# python scripts/mixedload.py -p expiry=10,count=10000,prefix=something,size=1024
3
4
5
6import sys
7import uuid
8
9sys.path.append('.')
10sys.path.append('lib')
11import TestInput
12from memcached.helper.data_helper import MemcachedClientHelper, VBucketAwareMemcached
13from membase.api.rest_client import RestConnection
14
15
16if __name__ == "__main__":
17    try:
18        input = TestInput.TestInputParser.get_test_input(sys.argv)
19        server = input.servers[0]
20        params = input.test_params
21        count = 0
22        prefix = str(uuid.uuid4())[:6]
23        count = 10 * 1000 * 1000 * 1000
24        size = 512
25        expiry = 0
26        if "count" in params:
27            count = int(params["count"])
28            print count
29        if "size" in params:
30            size = int(params["size"])
31        if "prefix" in params:
32            prefix = params["prefix"]
33        #if "expiry" in params:
34        #    expiry = int(params["expiry"])
35        payload = MemcachedClientHelper.create_value('*', size)
36        rest = RestConnection(server)
37        buckets = rest.get_buckets()
38        for bucket in buckets:
39            smart = VBucketAwareMemcached(rest, bucket.name)
40            mc = MemcachedClientHelper.proxy_client(server, bucket.name)
41            i = 0
42            counter_10 = 0
43            all_set = False
44            while i < count:
45                try:
46                    key = "{0}-{1}".format(prefix, i)
47                    #mc = smart.memcached(key)
48                    #do an expiry every 10 times
49                    if counter_10 >= 7:
50                        if all_set == True:
51                            mc.delete(key)
52                        mc.set(key, 0, 0, payload)
53                        if counter_10 == 10:
54                            counter_10 = 0
55                    else:
56                        mc.set(key, 0, 0, payload)
57                        mc.get(key)
58                    counter_10 += 1
59                    i += 1
60                    if i == int(count):
61                        all_set = True
62                        i = 0
63                except Exception as ex:
64                    #print ex
65                    #we need to initialize smart client
66                    #smart.done()
67                    #smart = VBucketAwareMemcached(rest, bucket.name)
68                    mc = MemcachedClientHelper.proxy_client(server, bucket.name)
69
70    except Exception as ex:
71        print ex
72
73
74
75
76