diff --git a/README.md b/README.md index b8398bb..70ec534 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,28 @@ pip3 install -r requirments.txt ## Usage -The use of this utility is not a fancy thing, just need to update the **[redis.json](./Scripts/redis.json)** with your redis connection details. Content of file should be like this:- +The use of this utility is not a fancy thing, just need to update the **[redis.json](./Scripts/redis.json)** with your redis connection details. +Values key_length, key_range, error_timeout, get_int, set_int, expire_seconds - is used only for GET and SET simultaneously operation in Redis. +key_length - how long is key - set as random string length n +key_range - how many keys is stored in REDIS +expire_seconds - how long key is stored in REDIS in seconds, if set to zero, then stored without time limit +error_timeout - if response is above this limit then event is registred as error, if set to zero then error_timout is ignored +get_int - set from 1 to 10 - how many get tasks is fired per user - to get proportion with set operations +set_int - set from 1 to 10 - how many set tasks is fired per user - to get proportion with get operations + +Content of file should be like this:- ```json { "redis_host": "18.215.118.208", "redis_port": "6379", - "redis_password": "" + "redis_password": "", + "key_length": 1000, + "key_range": 1000, + "expire_seconds": 1200, + "error_timeout": 60000, + "get_int": 1, + "set_int": 1 } ``` diff --git a/Scripts/redis_get_set.py b/Scripts/redis_get_set.py index 5868ea4..d00393e 100755 --- a/Scripts/redis_get_set.py +++ b/Scripts/redis_get_set.py @@ -5,6 +5,7 @@ This script will use locust as framework. Author:- OpsTree Solutions +Edited by: zviedris """ from random import randint @@ -28,13 +29,14 @@ def randStr(chars = string.ascii_uppercase + string.digits, N=10): return ''.join(random.choice(chars) for _ in range(N)) filename = "redis.json" - configs = load_config(filename) class RedisClient(object): def __init__(self, host=configs["redis_host"], port=configs["redis_port"], password=configs["redis_password"]): self.rc = redis.StrictRedis(host=host, port=port, password=password) + self.errorTime = configs["error_timeout"] + self.expirationTime = configs["expire_seconds"] def query(self, key, command='GET'): """Function to Test GET operation on Redis""" @@ -47,12 +49,16 @@ def query(self, key, command='GET'): except Exception as e: total_time = int((time.time() - start_time) * 1000) events.request_failure.fire( - request_type=command, name=key, response_time=total_time, exception=e) + request_type=command, name="get", response_time=total_time, response_length=1, exception=e) else: total_time = int((time.time() - start_time) * 1000) length = len(result) - events.request_success.fire( - request_type=command, name=key, response_time=total_time, response_length=length) + if self.errorTime > 0 and total_time > self.errorTime: + events.request_failure.fire( + request_type=command, name="get", response_time=total_time, response_length=length, exception="timeout exception") + else: + events.request_success.fire( + request_type=command, name="get", response_time=total_time, response_length=length) return result def write(self, key, value, command='SET'): @@ -60,18 +66,26 @@ def write(self, key, value, command='SET'): result = None start_time = time.time() try: - result = self.rc.set(key, value) + if self.expirationTime > 0: + result = self.rc.set(key, value, self.expirationTime) + else: + result = self.rc.set(key, value) if not result: result = '' except Exception as e: total_time = int((time.time() - start_time) * 1000) events.request_failure.fire( - request_type=command, name=key, response_time=total_time, exception=e) + request_type=command, name="set", response_time=total_time, response_length=1, exception=e) else: total_time = int((time.time() - start_time) * 1000) length = len(value) - events.request_success.fire( - request_type=command, name=key, response_time=total_time, response_length=length) + #if time is greater than normal timeout - it is registred as timeout + if self.errorTime > 0 and total_time > self.errorTime: + events.request_failure.fire( + request_type=command, name="set", response_time=total_time, response_length=length, exception="timeout exception") + else: + events.request_success.fire( + request_type=command, name="set", response_time=total_time, response_length=length) return result @@ -86,23 +100,17 @@ def __init__(self, *args, **kwargs): self.key = 'key1' self.value = 'value1' - @task(2) + #get task - get one random key + @task(configs["get_int"]) def get_time(self): - #for i in range(self.key_range): - i = randint(1, self.key_range-1) - self.key = 'key'+str(i) - self.client.query(self.key) + i = randint(1, self.key_range-1) + self.key = 'key'+str(i) + self.client.query(self.key) - @task(1) + #set task - set one random key + @task(configs["set_int"]) def write(self): - #for i in range(self.key_range): - i = randint(1, self.key_range-1) - self.key = 'key'+str(i) - self.value = randStr(N=self.key_length) - self.client.write(self.key, self.value) - -# @task(1) -# def get_key(self): -# var = str(randint(1, self.key_range-1)) -# self.key = 'key'+var -# self.value = 'value'+var + i = randint(1, self.key_range-1) + self.key = 'key'+str(i) + self.value = randStr(N=self.key_length) + self.client.write(self.key, self.value) diff --git a/Scripts/redis_orig.json b/Scripts/redis_orig.json index 0b4c88e..60774be 100644 --- a/Scripts/redis_orig.json +++ b/Scripts/redis_orig.json @@ -3,5 +3,9 @@ "redis_port": "$REDIS_PORT", "redis_password": "$REDIS_PW", "key_length": 5000, - "key_range": 1000 + "key_range": 1000, + "expire_seconds": 900, + "error_timeout": 60000, + "get_int": 1, + "set_int": 1 }