You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2014/09/11 16:03:43 UTC

svn commit: r1624295 - /qpid/proton/branches/examples/tutorial/db_common.py

Author: gsim
Date: Thu Sep 11 14:03:43 2014
New Revision: 1624295

URL: http://svn.apache.org/r1624295
Log:
Better batching for improved performance

Modified:
    qpid/proton/branches/examples/tutorial/db_common.py

Modified: qpid/proton/branches/examples/tutorial/db_common.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/examples/tutorial/db_common.py?rev=1624295&r1=1624294&r2=1624295&view=diff
==============================================================================
--- qpid/proton/branches/examples/tutorial/db_common.py (original)
+++ qpid/proton/branches/examples/tutorial/db_common.py Thu Sep 11 14:03:43 2014
@@ -28,6 +28,7 @@ class Db(object):
         self.events = events
         self.tasks = Queue.Queue()
         self.position = None
+        self.pending_events = []
         self.thread = threading.Thread(target=self._process)
         self.thread.daemon=True
         self.thread.start()
@@ -67,15 +68,13 @@ class Db(object):
             conn.execute("INSERT INTO records(id, description) VALUES (?, ?)", (id, data))
         else:
             conn.execute("INSERT INTO records(description) VALUES (?)", (data,))
-        conn.commit()
         if event:
-            self.events.trigger(event)
+            self.pending_events.append(event)
 
     def _delete(self, conn, id, event):
         conn.execute("DELETE FROM records WHERE id=?", (id,))
-        conn.commit()
         if event:
-            self.events.trigger(event)
+            self.pending_events.append(event)
 
     def _process(self):
         conn = sqlite3.connect(self.db)
@@ -83,4 +82,12 @@ class Db(object):
         with conn:
             while True:
                 f = self.tasks.get(True)
-                f(conn)
+                try:
+                    while True:
+                        f(conn)
+                        f = self.tasks.get(False)
+                except Queue.Empty: pass
+                conn.commit()
+                for event in self.pending_events:
+                    self.events.trigger(event)
+                self.pending_events = []



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org