# coding: utf-8 import redis import time import threading redis_master = '192.168.1.82' redis_slave = '192.168.5.150' redis_real_ip_list = ['192.168.5.22','192.168.5.23','192.168.5.24'] def tester(count_num): d = {} def rbserver(count_num): for x in range(count_num): slave_conn = redis.StrictRedis(host=redis_slave, port=6379, db=0) slave_id = slave_conn.info()['run_id'] if not d.get(slave_id): d[slave_id] = 1 else: d[slave_id] += 1 def theadmanager(func,*host): thread_list = [] start = time.clock() for x in range(5): if host: thread = threading.Thread(target=func,args = (count_num / 5, host[0])) else: thread = threading.Thread(target=func,args = (count_num / 5,)) thread_list.append(thread) for thread in thread_list: thread.start() for thread in thread_list: thread.join() return time.clock() - start def singeserver(count_num,host): for x in range(count_num): conn = redis.StrictRedis(host=host, port=6379, db=0) slave_id = conn.info()['run_id'] print 'load banlance:',theadmanager(rbserver) time.sleep(1) print 'single server:', theadmanager(singeserver,'192.168.5.22') tester(2000)