-
Notifications
You must be signed in to change notification settings - Fork 7
/
flusher.py
59 lines (46 loc) · 1.38 KB
/
flusher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Usage:
See bench-flusher.sh.
"""
import argparse
import logging
import time
import redis
parser = argparse.ArgumentParser(description="Flusher.")
parser.add_argument(
"-t",
"--ckptflush-interval",
default=1,
type=float,
help="Seconds to sleep between each (ckpt,flush) pair.")
args = parser.parse_args()
# Set up logging.
logging.basicConfig(format='%(asctime)s %(message)s')
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
# Singleton chain.
PORT = 6370
# # Every this many seconds, either checkpoint or flush.
# CKPT_FLUSH_INTERVAL_SECS = 1
# SLEEP_SECS = 1
# BEFORE_FLUSH_SLEEP_SECS = 1
def Main():
head_client = redis.StrictRedis('127.0.0.1', PORT)
try:
num_ckpted = 0
num_flushed = 0
log.info('Start.')
while True:
time.sleep(args.ckptflush_interval)
r = head_client.execute_command('TAIL.CHECKPOINT')
log.info('ckpt: %s' % r)
num_ckpted += r
# if BEFORE_FLUSH_SLEEP_SECS > 0:
# time.sleep(BEFORE_FLUSH_SLEEP_SECS)
r = head_client.execute_command('HEAD.FLUSH')
log.info('flush: %s' % r)
num_flushed += r
except Exception as e:
log.info("Exiting: checkpointed %d flushed %d" % (num_ckpted,
num_flushed))
if __name__ == '__main__':
Main()