[llvm-commits] [LNT] r163169 - /lnt/trunk/lnt/server/db/v4db.py

Michael Gottesman mgottesman at apple.com
Tue Sep 4 14:55:01 PDT 2012


Author: mgottesman
Date: Tue Sep  4 16:55:01 2012
New Revision: 163169

URL: http://llvm.org/viewvc/llvm-project?rev=163169&view=rev
Log:
[LNT] Updated v4db.py so that an engine is reused in between requests.

The reason to do this is that currently for every request we create a new engine,
which interferes with SQLAlchemy's internal connection caching. Specifically,
every time we create a new v4db, a new connection pool is created which
will not recycle its connections implying a continually increasing
amount of connections which never close, overwhelming the database.

Modified:
    lnt/trunk/lnt/server/db/v4db.py

Modified: lnt/trunk/lnt/server/db/v4db.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/db/v4db.py?rev=163169&r1=163168&r2=163169&view=diff
==============================================================================
--- lnt/trunk/lnt/server/db/v4db.py (original)
+++ lnt/trunk/lnt/server/db/v4db.py Tue Sep  4 16:55:01 2012
@@ -1,3 +1,9 @@
+
+try:
+    import threading
+except:
+    import dummy_threading as threading
+
 import sqlalchemy
 
 import lnt.testing
@@ -14,6 +20,8 @@
     """
 
     _db_updated = set()
+    _engine_lock = threading.Lock()
+    _engine = None
 
     class TestSuiteAccessor(object):
         def __init__(self, v4db):
@@ -65,7 +73,10 @@
             path = 'sqlite:///' + path
 
         self.path = path
-        self.engine = sqlalchemy.create_engine(path, echo=echo)
+        with V4DB._engine_lock:
+            if V4DB._engine is None:
+                V4DB._engine = sqlalchemy.create_engine(path, echo=echo)
+        self.engine = V4DB._engine
 
         # Update the database to the current version, if necessary. Only check
         # this once per path.





More information about the llvm-commits mailing list