dabo Commit
Revision 7199
Date: 2012-06-14 05:29:47 -0700 (Thu, 14 Jun 2012)
Author: Nate
Trac: http://trac.dabodev.com/changeset/7199

Changed:
U   trunk/dabo/db/dBackend.py
U   trunk/dabo/db/dCursorMixin.py

Log:
Rewrote the KeepAliveInterval to enhance performance.  I kept the same thread
structure but moved all of the object declarations to the front so they weren't
created with every iteration of the loop.  I also increased the sleep time to
5 seconds, which is long enough to not cause a problem, but short enough where
the application will end soon after the main is finished.  Lastly, I added a
lastExecuteTime to the dBackend object, which gets updated on a cursor execute
statement.  The KeepAliveInterval is timed from the last cursor execute 
statement
instead of a constantly running clock, further minimizing impact to the UI.
Now, even with a 10 second KeepAliveInterval, the performance impact to the app
is negligible. 


Diff:
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py   2012-06-12 13:08:02 UTC (rev 7198)
+++ trunk/dabo/db/dBackend.py   2012-06-14 12:29:47 UTC (rev 7199)
@@ -32,6 +32,7 @@
                self._connection = None
                # Reference to the cursor that is using this object
                self._cursor = None
+               self.lastExecuteTime = time.time() # For keep alive interval
 
 
        def isValidModule(self):
@@ -378,9 +379,9 @@
        def getUpdateTablePrefix(self, tbl, autoQuote=True):
                """
                By default, the update SQL statement will be in the form of
-               
+
                        tablename.fieldname
-               
+
                but some backends do no accept this syntax. If not, change
                this method to return an empty string, or whatever should
                preceed the field name in an update statement.
@@ -393,9 +394,9 @@
                """
                By default, the comparisons in the WHERE clauses of
                SQL statements will be in the form of
-               
+
                        tablename.fieldname
-               
+
                but some backends do no accept this syntax. If not, change
                this method to return an empty string, or whatever should
                preceed the field name in a comparison in the WHERE clause
@@ -587,20 +588,22 @@
                                self.backendObj = backendObj
 
                        def run(self):
-                               last_hit = time.time()
+                               kal = self.backendObj.KeepAliveInterval
+                               app = self.backendObj.Application
+                               con = self.backendObj._connection
+                               cur = con.cursor()
+
                                while True:
-                                       kal = self.backendObj.KeepAliveInterval
-                                       app = self.backendObj.Application
+                                       time.sleep(5)
+
                                        if kal is None or not app or 
getattr(app, "_finished", False):
                                                self._toStop = True
                                        if self._toStop:
                                                return
-                                       if time.time() - last_hit > kal:
-                                               con = 
self.backendObj._connection
-                                               cur = con.cursor()
+
+                                       if time.time() - 
self.backendObj.lastExecuteTime > kal:
                                                cur.execute("select 1")
-                                               last_hit = time.time()
-                                               time.sleep(0.1)
+                                               self.backendObj.lastExecuteTime 
= time.time()
 
                existingThread = getattr(self, "_keepAliveThread", None)
                if existingThread:

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2012-06-12 13:08:02 UTC (rev 7198)
+++ trunk/dabo/db/dCursorMixin.py       2012-06-14 12:29:47 UTC (rev 7199)
@@ -387,6 +387,9 @@
                                                _("DBQueryException encountered 
in execute(): %s\n%s") % (errMsg, sql))
                                raise dException.DBQueryException(errMsg)
 
+               # Set the last execute time in case there is a Keep Alive 
Interval
+               self.BackendObject.lastExecuteTime = time.time()
+
                # Some backend programs do odd things to the description
                # This allows each backend to handle these quirks individually.
                self.BackendObject.massageDescription(self)
@@ -436,6 +439,7 @@
                ac = self.AuxCursor
                self._syncAuxProperties()
                ac.execute(sql, params)
+               self.BackendObject.lastExecuteTime = time.time()
                return ac
 
 



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to