Commit 8669d107 authored by Hanno Schlichting's avatar Hanno Schlichting

Simplify key handling

parent aa7d9cb8
...@@ -77,6 +77,9 @@ del addCleanUp ...@@ -77,6 +77,9 @@ del addCleanUp
def make_key(catalog, query): def make_key(catalog, query):
if not query:
return None
indexes = catalog.indexes indexes = catalog.indexes
valueindexes = determine_value_indexes(indexes) valueindexes = determine_value_indexes(indexes)
key = keys = query.keys() key = keys = query.keys()
...@@ -108,10 +111,10 @@ class CatalogPlan(object): ...@@ -108,10 +111,10 @@ class CatalogPlan(object):
""" """
def __init__(self, catalog, query=None, threshold=0.1): def __init__(self, catalog, query=None, threshold=0.1):
self.init() self.init_timer()
self.catalog = catalog self.catalog = catalog
self.query = query self.query = query
self._key = None self.key = make_key(catalog, query)
self.threshold = threshold self.threshold = threshold
parent = aq_parent(catalog) parent = aq_parent(catalog)
...@@ -122,7 +125,7 @@ class CatalogPlan(object): ...@@ -122,7 +125,7 @@ class CatalogPlan(object):
path = tuple(parent.getPhysicalPath()) path = tuple(parent.getPhysicalPath())
self.cid = path self.cid = path
def init(self): def init_timer(self):
self.res = [] self.res = []
self.start_time = None self.start_time = None
self.interim = {} self.interim = {}
...@@ -138,7 +141,7 @@ class CatalogPlan(object): ...@@ -138,7 +141,7 @@ class CatalogPlan(object):
def benchmark(self): def benchmark(self):
# holds the benchmark of each index # holds the benchmark of each index
return self.prioritymap().get(self.key(), None) return self.prioritymap().get(self.key, None)
def plan(self): def plan(self):
benchmark = self.benchmark() benchmark = self.benchmark()
...@@ -151,11 +154,11 @@ class CatalogPlan(object): ...@@ -151,11 +154,11 @@ class CatalogPlan(object):
return [i[1] for i in ranking] return [i[1] for i in ranking]
def start(self): def start(self):
self.init() self.init_timer()
self.start_time = time.time() self.start_time = time.time()
benchmark = self.benchmark() benchmark = self.benchmark()
if benchmark is None: if benchmark is None:
self.prioritymap()[self.key()] = {} self.prioritymap()[self.key] = {}
def start_split(self, label, result=None): def start_split(self, label, result=None):
self.interim[label] = (time.time(), None) self.interim[label] = (time.time(), None)
...@@ -189,7 +192,7 @@ class CatalogPlan(object): ...@@ -189,7 +192,7 @@ class CatalogPlan(object):
self.end_time = time.time() self.end_time = time.time()
self.duration = self.end_time - self.start_time self.duration = self.end_time - self.start_time
key = self.key() key = self.key
benchmark = self.benchmark() benchmark = self.benchmark()
prioritymap = self.prioritymap() prioritymap = self.prioritymap()
prioritymap[key] = benchmark prioritymap[key] = benchmark
...@@ -213,22 +216,13 @@ class CatalogPlan(object): ...@@ -213,22 +216,13 @@ class CatalogPlan(object):
def result(self): def result(self):
return (self.duration, tuple(self.res)) return (self.duration, tuple(self.res))
def key(self):
if not self._key:
self._key = make_key(self.catalog, self.query)
return self._key
def log(self): def log(self):
# result of stopwatch # result of stopwatch
res = self.result() res = self.result()
if res[0] < self.threshold: if res[0] < self.threshold:
return return
# The key calculation takes a bit itself, we want to avoid that for key = self.key
# any fast queries. This does mean that slow queries get the key
# calculation overhead added to their runtime.
key = self.key()
reports_lock.acquire() reports_lock.acquire()
try: try:
if self.cid not in reports: if self.cid not in reports:
......
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