[storm] Profiling project: instrumenting find()

Bozo Dragojevic bozo.dragojevic at gmail.com
Thu Aug 4 09:01:08 UTC 2011


Jeroen Vermeulen <jtv at ...> writes:


> Are you suggesting to derive a class (from the Storm-backed class plus 
> the marker) on the fly every time a dereference calls find?  It's a 
> clever trick but I'm a bit worried that it may upset Storm.  I recently 
> ran into some problems with a class derived from a Storm-backed class. 
> That was relatively straightforward inheritance, but it caused problems 
> with Storm's property lookup.
> 


The general idea I'm suggesting is a wrapper instance of the first 
parameter on invocations of store.find() from reference.py. 

While trying to articulate it a bit more I found that subclassing the 
marker from the tuple() doesn't really give any benefit so here' a bit
more fleshed out example. Just one call site is fixed up and just store.find(). 

--- references.py	2010-10-01 15:19:12.000000000 +0200
+++ /tmp/references.py	2011-08-04 10:06:06.000000000 +0200
@@ -271,6 +271,11 @@
         else:
             self._relation2 = None
 
+class ReferenceLoad(object):
+    __slots__ = ('cls_spec', 'context')
+    def __init__(self, cls_spec, context):
+        self.cls_spec = cls_spec
+        self.context = context
 
 class BoundReferenceSetBase(object):
 
@@ -279,7 +284,7 @@
         if store is None:
             raise NoStoreError("Can't perform operation without a store")
         where = self._get_where_clause()
-        result = store.find(self._target_cls, where, *args, **kwargs)
+        result = store.find(ReferenceLoad(self._target_cls, self._local), 
+                                      where, *args, **kwargs)
         if self._order_by is not None:
             result.order_by(self._order_by)
         return result


$ diff -u store.py /tmp
--- store.py	2011-04-15 15:05:20.000000000 +0200
+++ /tmp/store.py	2011-08-04 10:06:49.000000000 +0200
@@ -208,6 +208,11 @@
         """
         if self._implicit_flush_block_count == 0:
             self.flush()
+        if isinstance(cls_spec, ReferenceLoad):
+            context = cls_spec.context
+            cls_spec = cls_spec.cls_spec
+        else:
+            context = # new toplevel context
         find_spec = FindSpec(cls_spec)
         where = get_where_for_args(args, kwargs, find_spec.default_cls)
         return self._result_set_factory(self, find_spec, where)



Bozzo




More information about the storm mailing list