summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-05 02:10:49 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-05 02:10:49 -0500
commit8e6b5ab1bd541d5f6267ebdbcca1389e00b00d02 (patch)
treef6898a03b1c252face6fe95a589483901f1ef5b2 /lib/sqlalchemy
parentbbe88372e8a6f4f96a3492b670732e10edacf282 (diff)
downloadsqlalchemy-8e6b5ab1bd541d5f6267ebdbcca1389e00b00d02.tar.gz
- reduce some pool overhead
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/base.py7
-rw-r--r--lib/sqlalchemy/pool.py47
2 files changed, 27 insertions, 27 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 77aa950c0..907b1930b 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -830,6 +830,7 @@ class Connection(Connectable):
"""
self.engine = engine
+ self.dialect = engine.dialect
self.__connection = connection or engine.raw_connection()
self.__transaction = None
self.should_close_with_result = close_with_result
@@ -887,12 +888,6 @@ class Connection(Connectable):
return c
@property
- def dialect(self):
- "Dialect used by this Connection."
-
- return self.engine.dialect
-
- @property
def closed(self):
"""Return True if this connection is closed."""
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index 02d56dead..58b3a39c1 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -61,6 +61,8 @@ def clear_managers():
class Pool(log.Identified):
"""Abstract base class for connection pools."""
+ _no_finalize = False
+
def __init__(self,
creator, recycle=-1, echo=None,
use_threadlocal=False,
@@ -226,19 +228,13 @@ class Pool(log.Identified):
has its ``close()`` method called.
"""
- if self._use_threadlocal and hasattr(self._threadconns, "current"):
- del self._threadconns.current
+ if self._use_threadlocal:
+ try:
+ del self._threadconns.current
+ except AttributeError:
+ pass
self._do_return_conn(record)
- def _get(self):
- """Return a non-instrumented DBAPI connection from this :class:`.Pool`.
-
- This is called by ConnectionRecord in order to get its DBAPI
- resource.
-
- """
- return self._do_get()
-
def _do_get(self):
"""Implementation for :meth:`get`, supplied by subclasses."""
@@ -324,12 +320,14 @@ class _ConnectionRecord(object):
raise
-def _finalize_fairy(connection, connection_record, pool, ref=None):
+def _finalize_fairy(connection, connection_record, pool, ref, echo):
_refs.discard(connection_record)
+
+ if pool._no_finalize:
+ return
if ref is not None and \
- (connection_record.fairy is not ref or
- isinstance(pool, AssertionPool)):
+ connection_record.fairy is not ref:
return
if connection is not None:
@@ -347,7 +345,9 @@ def _finalize_fairy(connection, connection_record, pool, ref=None):
if connection_record is not None:
connection_record.fairy = None
- pool.logger.debug("Connection %r being returned to pool", connection)
+ if echo:
+ pool.logger.debug("Connection %r being returned to pool",
+ connection)
if pool.dispatch.on_checkin:
pool.dispatch.on_checkin(connection, connection_record)
pool._return_conn(connection_record)
@@ -359,17 +359,19 @@ class _ConnectionFairy(object):
support."""
__slots__ = '_pool', '__counter', 'connection', \
- '_connection_record', '__weakref__', '_detached_info'
+ '_connection_record', '__weakref__', \
+ '_detached_info', '_echo'
def __init__(self, pool):
self._pool = pool
self.__counter = 0
+ self._echo = _echo = pool._should_log_debug()
try:
- rec = self._connection_record = pool._get()
+ rec = self._connection_record = pool._do_get()
conn = self.connection = self._connection_record.get_connection()
rec.fairy = weakref.ref(
self,
- lambda ref:_finalize_fairy(conn, rec, pool, ref)
+ lambda ref:_finalize_fairy(conn, rec, pool, ref, _echo)
)
_refs.add(rec)
except:
@@ -377,7 +379,8 @@ class _ConnectionFairy(object):
self.connection = None
self._connection_record = None
raise
- self._pool.logger.debug("Connection %r checked out from pool" %
+ if self._echo:
+ self._pool.logger.debug("Connection %r checked out from pool" %
self.connection)
@property
@@ -482,7 +485,8 @@ class _ConnectionFairy(object):
self._close()
def _close(self):
- _finalize_fairy(self.connection, self._connection_record, self._pool)
+ _finalize_fairy(self.connection, self._connection_record,
+ self._pool, None, self._echo)
self.connection = None
self._connection_record = None
@@ -822,7 +826,8 @@ class AssertionPool(Pool):
than desired.
"""
-
+ _no_finalize = True
+
def __init__(self, *args, **kw):
self._conn = None
self._checked_out = False