]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added profiling to massave
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 1 Oct 2006 23:15:53 +0000 (23:15 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 1 Oct 2006 23:15:53 +0000 (23:15 +0000)
- adjusted the formatting for per-instance loggers to limit the number
of loggers that get created in memory.

lib/sqlalchemy/logging.py
test/perf/masssave.py

index bba1e0764bbb2f76b89d49ff49d12d3cb87778d4..bbd008dac156ad951f8dc768f0b47c59c882927d 100644 (file)
@@ -40,8 +40,10 @@ def default_logging():
         handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s'))
         rootlogger.addHandler(handler)
 
-def _get_instance_name(instance):                    
-    return instance.__class__.__module__ + "." + instance.__class__.__name__ + "." + hex(id(instance))
+def _get_instance_name(instance):
+    # since getLogger() does not have any way of removing logger objects from memory,
+    # instance logging displays the instance id as a modulus of 10 to prevent endless memory growth
+    return instance.__class__.__module__ + "." + instance.__class__.__name__ + ".0x.." + hex(id(instance))[-2:]
     
 def instance_logger(instance):
     return logging.getLogger(_get_instance_name(instance))
index 0ffb3455322557df49e8091b92c2eb3a92e9304d..8e4d5e3fff5cbe1d228d5207ef9eb00ac234a71c 100644 (file)
@@ -5,10 +5,11 @@ import sqlalchemy.attributes as attributes
 import StringIO
 import testbase
 import gc
-
+import sqlalchemy.orm.session
+import types
 db = testbase.db
 
-NUM = 25000
+NUM = 250000
 
 class SaveTest(AssertMixin):
     def setUpAll(self):
@@ -27,13 +28,29 @@ class SaveTest(AssertMixin):
             
         m = mapper(Item, items)
         
-        for x in range(0,100):
+        for x in range(0,NUM/50):
             sess = create_session()
             query = sess.query(Item)
             for y in range (0,50):
-                print "x,y", (x,y)
#               print "x,y", (x,y)
                 sess.save(Item())
             sess.flush()
-
+            #self._profile()
+            print "ROWS:", x * 50
+    def _profile(self):
+        print "------------------------"
+        d = {}
+        for o in gc.get_objects():
+            t = type(o)
+            if t is types.InstanceType:
+                t = o.__class__
+            d.setdefault(t, 0)
+            d[t] += 1
+        rep = [(key, value) for key, value in d.iteritems()]
+        def sorter(a, b):
+            return cmp(b[1], a[1])
+        rep.sort(sorter)
+        for x in rep[0:30]:
+            print x
 if __name__ == "__main__":
     testbase.main()