Browse Source

Add instrumentation

master
Neil Booth 8 years ago
parent
commit
7b36a1431c
  1. 11
      server/db.py

11
server/db.py

@ -191,13 +191,16 @@ class DB(object):
with self.db.write_batch(transaction=True) as batch: with self.db.write_batch(transaction=True) as batch:
# Flush the state, then the cache, then the history # Flush the state, then the cache, then the history
self.put_state() self.put_state()
for key, value in self.write_cache.items(): for n, (key, value) in enumerate(self.write_cache.items()):
if value is None: if value is None:
batch.delete(key) batch.delete(key)
deletes += 1 deletes += 1
else: else:
batch.put(key, value) batch.put(key, value)
writes += 1 writes += 1
if n % 1000 == 0:
pct = n // len(self.write_cache) * 100
self.logger.info('{:d} {:d}% done...'.format(n, pct))
self.flush_history() self.flush_history()
@ -220,7 +223,7 @@ class DB(object):
# Drop any None entry # Drop any None entry
self.history.pop(None, None) self.history.pop(None, None)
for hash160, hist in self.history.items(): for m, (hash160, hist) in enumerate(self.history.items()):
prefix = b'H' + hash160 prefix = b'H' + hash160
for key, v in self.db.iterator(reverse=True, prefix=prefix, for key, v in self.db.iterator(reverse=True, prefix=prefix,
fill_cache=False): fill_cache=False):
@ -245,6 +248,10 @@ class DB(object):
.format(addr, idx)) .format(addr, idx))
self.db.put(key, v[n:n + HIST_ENTRY_LEN]) self.db.put(key, v[n:n + HIST_ENTRY_LEN])
if m % 1000 == 0:
pct = m // len(self.history) * 100
self.logger.info('{:d} {:d}% done...'.format(m, pct))
self.history = defaultdict(list) self.history = defaultdict(list)
def get_hash160(self, tx_hash, idx, delete=True): def get_hash160(self, tx_hash, idx, delete=True):

Loading…
Cancel
Save