Skip to content

Commit

Permalink
changing config to read from env vars instead of config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ruebenramirez committed Apr 27, 2015
1 parent 6b4c677 commit aca260b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 57 deletions.
6 changes: 6 additions & 0 deletions ENV_EXAMPLE
Original file line number Diff line number Diff line change
@@ -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=''
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ 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.)
* simulate redis usage scenarios: blowout, linear increase, exponential increase, variable pattern, high/medium/low trigger patterns, etc.)
* 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


60 changes: 27 additions & 33 deletions redisMaxOut.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

10 changes: 0 additions & 10 deletions setup.cfg.EXAMPLE

This file was deleted.

3 changes: 2 additions & 1 deletion setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

pip install virtualenv
virtualenv .venv
source .venv/bin/activate
pip install redis

0 comments on commit aca260b

Please sign in to comment.