def get_poller_stats_ex(self): return dict(all_count=self.rc.zcard(S1.gid_set('all')), pollers=self.get_poller_stats(), poller_names=list(self.rc.smembers(S1.poller_set())), register_set_len=self.rc.scard(S1.register_set()), poll_list_len=self.rc.llen(S1.poller_channel_name('all')))
def dump_gids(self): total = 0 c = self.data.rc.hscan(S1.destination_key_fmt('children')) while len(c) > 1 and c[1]: total += len(c[1]) for gid in c[1]: self.dump_gid(gid) # check if the next cursor is zero if c[0] == '0' or c[0] == 0: break # grab next set c = self.data.rc.hscan(S1.destination_key_fmt('children'), c[0]) # sleep 10 sec before retry print('End of gid_set, total [{0}] GIDs.'.format(total)) self.data_d.rc.delete(S1.register_set()) print('Cleared register set.')
parser.add_argument('--period', default=60, type=int) args = parser.parse_args() logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S') logger = logging.getLogger(__name__) logger.addHandler( config.getLogHandler(os.path.join(args.log_path, 'poller_test.log'))) logger.level = logging.DEBUG data = data.Data(logger, args.redis_host, args.redis_port, args.redis_db) while True: logger.warning( 'Invoking poll for all, next poll in {0} seconds'.format( args.period)) with open(args.gid_set) as f_set: gid_set = [gid.strip() for gid in f_set.readlines()] logger.info('Read [{0}] gids'.format(len(gid_set))) for n in range(0, len(gid_set)): gid = gid_set[randint(0, len(gid_set) - 1)] logger.info('Invoking rebalance for [{0}]'.format(gid)) data.rc.sadd(S1.register_set(), gid) data.register_gid(gid) t = randint(5, 20) logger.info('Sleeping for [{0}]'.format(t)) time.sleep(t) #get delay and wait time.sleep(args.period)
def get_next_registered(self): return self.rc.spop(S1.register_set())
def register_gid(self, gid): # add to balance list self.rc.sadd(S1.register_set(), gid) # notify poller(s) self.pubsub.broadcast_command_now(S1.poller_channel_name('all'), S1.msg_register())