Commit f58a0627 authored by Tomas Krizek's avatar Tomas Krizek

orchestrator: measure total duration of execution

Fixes https://gitlab.labs.nic.cz/knot/resolver-benchmarking/issues/26
parent 89fd557c
class Reply:
def __init__(self, wire: bytes, duration: float) -> None:
self.wire = wire
self.duration = duration
......@@ -6,6 +6,7 @@ import lmdb
ANSWERS_DB_NAME = b'answers'
DIFFS_DB_NAME = b'diffs'
QUERIES_DB_NAME = b'queries'
STATS_DB_NAME = b'stats'
env_open = {
......
......@@ -95,6 +95,7 @@ def print_results(gstats, field_weights, counters, n=10):
maxcntlen = maxlen(gstats.values())
print('== Global statistics')
print('duration {:{}} s'.format(gstats['duration'], maxcntlen))
print('queries {:{}}'.format(gstats['queries'], maxcntlen))
print('answers {:{}} {:6.2f} % of queries'.format(
gstats['answers'], maxcntlen, float(100) * gstats['answers'] / gstats['queries']))
......@@ -179,11 +180,12 @@ def open_db(envdir):
qdb = lenv.open_db(key=dbhelper.QUERIES_DB_NAME, create=False, **dbhelper.db_open)
adb = lenv.open_db(key=dbhelper.ANSWERS_DB_NAME, create=False, **dbhelper.db_open)
ddb = lenv.open_db(key=dbhelper.DIFFS_DB_NAME, create=False, **dbhelper.db_open)
sdb = lenv.open_db(key=dbhelper.STATS_DB_NAME, create=False, **dbhelper.db_open)
except lmdb.NotFoundError:
logging.critical(
'Unable to generate statistics. LMDB does not contain queries, answers, or diffs!')
raise
return lenv, qdb, adb, ddb
return lenv, qdb, adb, ddb, sdb
def read_diffs_lmdb(levn, qdb, ddb):
......@@ -208,12 +210,15 @@ def main():
config = cfg.read_cfg(args.cfgpath)
field_weights = config['report']['field_weights']
lenv, qdb, adb, ddb = open_db(args.envdir)
lenv, qdb, adb, ddb, sdb = open_db(args.envdir)
diff_stream = read_diffs_lmdb(lenv, qdb, ddb)
global_stats, field_stats = process_results(field_weights, diff_stream)
with lenv.begin() as txn:
global_stats['queries'] = txn.stat(qdb)['entries']
global_stats['answers'] = txn.stat(adb)['entries']
with lenv.begin(sdb) as txn:
stats = pickle.loads(txn.get(b'global_stats'))
global_stats['duration'] = round(stats['end_time'] - stats['start_time'])
print_results(global_stats, field_weights, field_stats)
......
......@@ -14,6 +14,7 @@ import dns.exception
import lmdb
import cfg
import dataformat
import dbhelper
......
......@@ -5,6 +5,7 @@ import multiprocessing.pool as pool
import pickle
import sys
import threading
import time
import logging
import lmdb
......@@ -75,7 +76,8 @@ def lmdb_init(envdir):
create=False,
**dbhelper.db_open)
adb = lenv.open_db(key=dbhelper.ANSWERS_DB_NAME, create=True, **dbhelper.db_open)
return (lenv, qdb, adb)
sdb = lenv.open_db(key=dbhelper.STATS_DB_NAME, create=True, **dbhelper.db_open)
return (lenv, qdb, adb, sdb)
def main():
......@@ -108,8 +110,12 @@ def main():
args.envdir, dbhelper.ANSWERS_DB_NAME)
sys.exit(1)
lenv, qdb, adb = lmdb_init(args.envdir)
lenv, qdb, adb, sdb = lmdb_init(args.envdir)
qstream = dbhelper.key_value_stream(lenv, qdb)
stats = {
'start_time': time.time(),
'end_time': None,
}
with lenv.begin(adb, write=True) as txn:
with pool.Pool(
......@@ -119,6 +125,10 @@ def main():
for qid, blob in p.imap(worker_query_lmdb_wrapper, qstream, chunksize=100):
txn.put(qid, blob)
stats['end_time'] = time.time()
with lenv.begin(sdb, write=True) as txn:
txn.put(b'global_stats', pickle.dumps(stats))
if __name__ == "__main__":
main()
......@@ -7,6 +7,8 @@ import struct
import dns.inet
import dns.message
import dataformat
def sock_init(resolvers):
"""
......@@ -91,7 +93,7 @@ def send_recv_parallel(dgram, selector, sockets, timeout):
# assert len(wire) > 14
if dgram[0:2] != wire[0:2]:
continue # wrong msgid, this might be a delayed answer - ignore it
replies[name] = wire
replies[name] = dataformat.Reply(wire, None)
if not events:
break # TIMEOUT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment