diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-04-12 11:37:19 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-04-12 12:53:40 -0400 |
| commit | cef4e5ff38dc7d2200800837c110ab6beec10d8a (patch) | |
| tree | 24eac58c1fb6e3105c9c4c7046d1aa2b5259a67d /doc/build/faq | |
| parent | 1b463058e3282c73d0fb361f78e96ecaa23ce9f4 (diff) | |
| download | sqlalchemy-cef4e5ff38dc7d2200800837c110ab6beec10d8a.tar.gz | |
Warn on _compiled_cache growth
Added warnings to the LRU "compiled cache" used by the :class:`.Mapper`
(and ultimately will be for other ORM-based LRU caches) such that
when the cache starts hitting its size limits, the application will
emit a warning that this is a performance-degrading situation that
may require attention. The LRU caches can reach their size limits
primarily if an application is making use of an unbounded number
of :class:`.Engine` objects, which is an antipattern. Otherwise,
this may suggest an issue that should be brought to the SQLAlchemy
developer's attention.
Additionally, adjusted the test_memusage algorithm again as the
previous one could still allow a growing memory size to be missed.
Change-Id: I020d1ceafb7a08f6addfa990a1e7acd09f933240
Diffstat (limited to 'doc/build/faq')
| -rw-r--r-- | doc/build/faq/performance.rst | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/doc/build/faq/performance.rst b/doc/build/faq/performance.rst index 3b76c8326..61c0d6ea2 100644 --- a/doc/build/faq/performance.rst +++ b/doc/build/faq/performance.rst @@ -459,3 +459,54 @@ Script:: test_sqlalchemy_core(100000) test_sqlite3(100000) + +.. _faq_compiled_cache_threshold: + +How do I deal with "compiled statement cache reaching its size threshhold"? +----------------------------------------------------------------------------- + +Some parts of the ORM make use of a least-recently-used (LRU) cache in order +to cache generated SQL statements for fast reuse. More generally, these +areas are making use of the "compiled cache" feature of :class:`.Connection` +which can be invoked using :meth:`.Connection.execution_options`. + +The following two points summarize what should be done if this warning +is occurring: + +* Ensure the application **does not create an arbitrary number of + Engine objects**, that is, it does not call :func:`.create_engine` on + a per-operation basis. An application should have only **one Engine per + database URL**. + +* If the application does not have an unbounded number of engines, + **report the warning to the SQLAlchemy developers**. Guidelines on + mailing list support is at: http://www.sqlalchemy.org/support.html#mailinglist + +The cache works by creating a cache key that can uniquely identify the +combination of a specific **dialect** and a specific **Core SQL expression**. +A cache key that already exists in the cache will reuse the already-compiled +SQL expression. A cache key that doesn't exist will create a *new* entry +in the dictionary. When this dictionary reaches the configured threshhold, +the LRU cache will *trim the size* of the cache back down by a certain percentage. + +It is important to understand that from the above, **a compiled cache that +is reaching its size limit will perform badly.** This is because not only +are the SQL statements being freshly compiled into strings rather than using +the cached version, but the LRU cache is also spending lots of time trimming +its size back down. + +The primary reason the compiled caches can grow is due to the **antipattern of +using a new Engine for every operation**. Because the compiled cache +must key on the :class:`.Dialect` associated with an :class:`.Engine`, +calling :func`.create_engine` many times in an application will establish +new cache entries for every engine. Because the cache is self-trimming, +the application won't grow in size unbounded, however the application should +be repaired to not rely on an unbounded number of :class:`.Engine` +objects. + +Outside of this pattern, the default size limits set for these caches within +the ORM should not generally require adjustment, and the LRU boundaries +should never be reached. If this warning is occurring and the application +is not generating hundreds of engines, please report the issue to the +SQLAlchemy developers on the mailing list; see the guidelines +at http://www.sqlalchemy.org/support.html#mailinglist.
\ No newline at end of file |
