Exemplo n.º 1
0
    def __init__(self):
        threading.Thread.__init__(self)

        op, path = config.select_config(config.find_configs(), 3)
        cfg = config.from_file(path)

        self.rc = redis.Redis(host=cfg["host"], port=int(cfg["port"]))

        if cfg.has_key("auth") and (cfg["auth"] is not None):
            self.rc.execute_command("AUTH", cfg["auth"])
Exemplo n.º 2
0
def select_db(): #/*{{{*/
    quit = True

    op,path = config.select_config(config.find_configs())
    if op == "quit":
        return quit

    cfg = config.from_file(path)
    again = True
    last_connect = 0.0
    db = None

    while again: 
        try:
            connect_time = time.time()
            if connect_time - last_connect < 0.25:
                again = False
                quit = False
                continue

            last_connect = connect_time
            again = False

            if (db is not None):
                del db
                db = None

            db = Database(cfg)
            print "Connected to Redis server:  %(host)s:%(port)s" % cfg

            cli = CommandLine(db)
            cli.loop()
            quit = cli.done
            del db
            db = None
        except KeyError, ex:
            print "Malformed config key '%s' in %s" % (str(ex), path)
            sys.exit(1)
        except redis.ConnectionError, ex:
            print ex
            quit = False
Exemplo n.º 3
0
def test_connections(): #/*{{{*/
	quit = True

	op,path = config.select_config(config.find_configs())
	if op == "quit":
		return quit

	cfg = config.from_file(path)
	again = True
	last_connect = 0.0

	connections = []

	count = 0
	max_connections = 1000
	max_iterations = 10
	iteration = 0

	total_conn_ms = 0.0
	total_read_ms = 0.0
	total_write_ms = 0.0

	while True: 
		try:
			if len(connections) < max_connections:
				start = time.time()
				conn = redis.Redis(host=cfg['host'], port=int(cfg['port']))
				if cfg.has_key('auth'):
					print conn.execute_command('AUTH', cfg['auth'])
				end = time.time()

				connect_time = (end - start) * 1000.0
				total_conn_ms += connect_time

				connections.append(conn)

				print "Connection #", len(connections), "established in", connect_time, "ms"

			else:
				conn_num = 0
				for conn in connections:
					start = time.time()
					previous_value = conn.execute_command('GET', 'COUNT')
					end = time.time()
					read_time = (end - start) * 1000.0
					
					start = time.time()
					conn.execute_command('INCR', 'COUNT')
					end = time.time()
					write_time = (end - start) * 1000.0

					print "Connection #", conn_num, ":", previous_value, "[read", read_time, "ms]", "[write", write_time, "ms]"
					conn_num += 1
					count += 1

					total_read_ms += read_time
					total_write_ms += write_time

				iteration += 1

				if iteration > max_iterations:
					average_conn_ms = total_conn_ms / count
					average_read_ms = total_read_ms / count
					average_write_ms = total_write_ms / count
					print
					print "Averages:", "[connect", average_conn_ms, "ms]", "[read", average_read_ms, "ms]", "[write", average_write_ms, "ms]"
					sys.exit(0)

		except KeyError, ex:
			print "Malformed config key '%s' in %s" % (str(ex), path)
			sys.exit(1)
		except redis.ConnectionError, ex:
			print "Connection error", str(ex)
Exemplo n.º 4
0
#!/usr/bin/env python
import os
import random
import re
import readline
from redis import config
import sys
import time

op,path = config.select_config(config.find_configs())
if op.lower() == "quit":
    sys.exit(0)
cfg = config.from_file(path)

try:
    command = "redis-cli -h %(host)s -p %(port)s -a %(auth)s" % cfg
    sys.exit(os.system(command))
except KeyError, ex:
    print "Malformed config key '%s' in %s" % (str(ex), config_file)
    sys.exit(1)
except Exception, ex:
    print "Could not connect to database. Details: %s" % str(ex)
    sys.exit(1)

Exemplo n.º 5
0
def test_connections(thread_count, iterations, redis_config_index=None): #/*{{{*/
    quit = True

    op,path = config.select_config(config.find_configs(), redis_config_index)

    if op == "quit":
        return quit

    cfg = config.from_file(path)
    again = True
    last_connect = 0.0

    threads = []

    start_time = time.time() + (thread_count / 2000.0)

    all_conn_ms = []
    min_conn_ms = 2.0 ** 31.0
    med_conn_ms = 0.0
    avg_conn_ms = 0.0
    max_conn_ms = 0.0
    total_conn_ms = 0.0

    all_read_ms = []
    min_read_ms = 2.0 ** 31.0
    med_read_ms = 0.0
    avg_read_ms = 0.0
    max_read_ms = 0.0
    total_read_ms = 0.0

    all_write_ms = []
    min_write_ms = 2.0 ** 31.0
    med_write_ms = 0.0
    avg_write_ms = 0.0
    max_write_ms = 0.0
    total_write_ms = 0.0

    failure_count = 0

    try:
        conn_id = 0
        while len(threads) < thread_count:
            thread = ConnectionThread(iterations, conn_id, cfg, start_time)
            threads.append(thread)
            conn_id += 1

        sys.stdout.write("Starting threads...\n")
        for thread in threads:
            thread.start()
        sys.stdout.write("%d threads started.\n" % thread_count)

        while (start_time - time.time()) > 0.25:
            wait = start_time - time.time()
            sys.stdout.write("T -%f\n" % wait)
            time.sleep(0.25)

        sys.stdout.write("Waiting for threads to complete...\n")
        for thread in threads:
            thread.join()

        for thread in threads:
            all_conn_ms.append(thread.get_connect_time())
            total_conn_ms += thread.get_connect_time()
            if thread.get_connect_time() > max_conn_ms:
                max_conn_ms = thread.get_connect_time()
            if thread.get_connect_time() < min_conn_ms:
                min_conn_ms = thread.get_connect_time()

            all_read_ms.append(thread.get_average_read_time())
            total_read_ms += thread.get_average_read_time()
            if thread.get_average_read_time() > max_read_ms:
                max_read_ms = thread.get_average_read_time()
            if thread.get_average_read_time() < min_read_ms:
                min_read_ms = thread.get_average_read_time()

            all_write_ms.append(thread.get_average_write_time())
            total_write_ms += thread.get_average_write_time()
            if thread.get_average_write_time() > max_write_ms:
                max_write_ms = thread.get_average_write_time()
            if thread.get_average_write_time() < min_write_ms:
                min_write_ms = thread.get_average_write_time()

            if thread.failed:
                sys.stdout.write("Connection # %d failed after %d iterations\n" % (thread.connection_id, thread.iteration_count))
                failure_count += 1

        info = threads[0].conn.execute_command('INFO')
        maxKeyLen = max(map(len, info.keys()))
        
        for k,v in sorted(info.items()):
            print str(k + " ").ljust(maxKeyLen + 1, "-"), v


        avg_conn_ms = total_conn_ms / thread_count
        avg_read_ms = total_read_ms / thread_count
        avg_write_ms = total_write_ms / thread_count

        med_conn_ms = sorted(all_conn_ms)[len(all_conn_ms) / 2]
        med_read_ms = sorted(all_read_ms)[len(all_read_ms) / 2]
        med_write_ms = sorted(all_write_ms)[len(all_write_ms) / 2]

        sys.stdout.write("\n%s clients connected\n" % info['connected_clients'])
        sys.stdout.write("\nFailed: %d\n" % failure_count)
        sys.stdout.write("Connect: [min %f ms] [median %f ms] [average %f ms] [max %f ms]\n" % (min_conn_ms, med_conn_ms, avg_conn_ms, max_conn_ms))
        sys.stdout.write("Read:    [min %f ms] [median %f ms] [average %f ms] [max %f ms]\n" % (min_read_ms, med_read_ms, avg_read_ms, max_read_ms))
        sys.stdout.write("Write:   [min %f ms] [median %f ms] [average %f ms] [max %f ms]\n" % (min_write_ms, med_write_ms, avg_write_ms, max_write_ms))

    except KeyError, ex:
        print "Malformed config key '%s' in %s" % (str(ex), path)
        sys.exit(1)