diff --git a/ENV_EXAMPLE b/ENV_EXAMPLE new file mode 100644 index 0000000..84da497 --- /dev/null +++ b/ENV_EXAMPLE @@ -0,0 +1,6 @@ +REDIS_MAXOUT_HOST='localhost' +REDIS_MAXOUT_PORT=6379 +REDIS_MAXOUT_PASSWORD='' +REDIS_MAXOUT_LOOP_ITERATIONS='' +REDIS_MAXOUT_LOOP_VALUE_MULTIPLIER='' +REDIS_MAXOUT_LOOP_PRINT_ITER='' diff --git a/README.md b/README.md index f938b5c..8e94a42 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,11 @@ max out redis memory store to test max memory key eviction policy settings ###Configure via Setup.cfg -1. copy example.setup.cfg to setup.cfg -1. update the connection details +1. update the connection details in the ENV_EXAMPLE file 1. modify the loop config details to tweak the iteration count and value size assigned to each key +1. deploy your environment variables: `export cat ENV_EXAMPLE` ###TODO - * add more exception handling and clean up the run to make it a usable tool * report on redis configuraiton as an option * change redis configuration settings (e.g. eviction policy, eviction sample size, etc.) @@ -18,3 +17,5 @@ max out redis memory store to test max memory key eviction policy settings * provide metrics on the run (key eviction accuracy in max memory scenarios) * ready this tool to test cluster configurations * add support for expires on some/all keys + + diff --git a/redisMaxOut.py b/redisMaxOut.py index cab5670..c747965 100755 --- a/redisMaxOut.py +++ b/redisMaxOut.py @@ -1,37 +1,43 @@ #!/usr/bin/python -from sys import argv -import ConfigParser, os -import redis +import os import datetime import hashlib +import redis + + class MaxOutConfig(): def __init__(self): self.read_config() - - def read_config(self): - try: - config_file = argv[1] - except IndexError: - config_file = 'setup.cfg' - - config = ConfigParser.ConfigParser() - config.readfp(open(config_file)) + def read_config(self): # connection settings - self.url = str(config.get('redis connection', 'url')) - self.port = int(config.get('redis connection', 'port')) - self.password = str(config.get('redis connection', 'password')) + self.host = os.environ['REDIS_MAXOUT_HOST'] + self.port = os.environ['REDIS_MAXOUT_PORT'] + self.password = os.environ['REDIS_MAXOUT_PASSWORD'] + # TODO: do we even need these? # loop handler settings - self.iterations = int(config.get('loop', 'iterations')) - self.value_multiplier = int(config.get('loop', 'value_multiplier')) - self.print_iter = int(config.get('loop', 'print_iter')) + self.iterations = os.environ['REDIS_MAXOUT_LOOP_ITERATIONS'] + self.value_multiplier = os.environ['REDIS_MAXOUT_LOOP_VALUE_MULTIPLIER'] + self.print_iter = os.environ['REDIS_MAXOUT_LOOP_PRINT_ITER'] + + # check config settings + self.validate_config() + + def validate_config(self): + if self.host is None: + raise Exception('Please specify a Redis host') + if self.port is None: + raise Exception('Please specify a Redis port') + if not self.port.isdigit(): + raise Exception('Please specify numeric Redis port') + class MaxOut(): def __init__(self, config): - self.url = config.url + self.host = config.host self.port = config.port self.password = config.password self.iterations = config.iterations @@ -40,25 +46,13 @@ def __init__(self, config): self.connect() def connect(self): - self.r_server = redis.Redis(self.url, - port = self.port, - password = self.password) - - def validate_config(self): - # TODO check connection - # TODO check loop config - - # FIXME stub - return True + self.r_server = redis.Redis(self.host, port=self.port, + password=self.password) def flush(self): self.r_server.flushall() def max_out(self): - if(not self.validate_config()): - print 'exiting...invalid configuration' - return - for x in range(0, self.iterations): m = hashlib.md5() my_date = datetime.datetime.today() diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 672b184..0000000 --- a/setup.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[redis connection] -url=greeneye.redistogo.com -port=11813 -password=b9c5a5d2c93334b42f453b88840295cf - -[loop] -iterations=900 -value_multiplier=500 -print_iter=100 - diff --git a/setup.cfg.EXAMPLE b/setup.cfg.EXAMPLE deleted file mode 100644 index 9d35037..0000000 --- a/setup.cfg.EXAMPLE +++ /dev/null @@ -1,10 +0,0 @@ -[redis connection] -url=localhost -port=6379 -password= - -[loop] -iterations=900 -value_multiplier=500 -print_iter=100 - diff --git a/setup.sh b/setup.sh old mode 100644 new mode 100755 index 91d137c..05fd7e3 --- a/setup.sh +++ b/setup.sh @@ -1,5 +1,6 @@ #!/bin/bash pip install virtualenv +virtualenv .venv +source .venv/bin/activate pip install redis -