Well, this doesn't look like an Elixir-specific problem, so if what I
say below doesn't help you, you'll probably get better answers on the
SQLAlchemy list. A search in its archive could also help.

On Mon, Feb 16, 2009 at 21:39, Mykola Paliyenko <[email protected]> wrote:

> Just added cache decorator to the method that look like
>
>    @beaker_cache(expire=600, type='memory', key=["limit",
> "category_id", "company_id"])
>    def recent_products(self, limit, category_id=None,
> company_id=None):
>        query = Product.query.select_from(
>            Product.table.join(Company.table)
>        ).filter(and_(Company.status == Company.STATUS_ACTIVE,
> Product.status == Product.STATUS_ON_DISPLAY, Company.content_quality >
> 0.4))
>        if category_id:
>            query = query.filter_by(category_id=category_id)
>        if company_id:
>            query = query.filter_by(company_id=company_id)
>        query = query.order_by(Product.date_created.desc())
>        return query.limit(limit)
>
> And after some time I get
>
> File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.4.5-py2.5.egg/
> sqlalchemy/pool.py", line 587, in do_get
>   raise exceptions.TimeoutError("QueuePool limit of size %d overflow
> %d reached, connection timed out, timeout %d" % (self.size(),
> self.overflow(), self._timeout))
> TimeoutError: QueuePool limit of size 5 overflow 20 reached,
> connection timed out, timeout 30
>
> What is the root of problem here? Is it that I cache query but not the
> objects

Yep, that's likely.

> and then after query get detached from session

The query never gets in the session (nor does it get detached from
it). The objects do. What I *think* happens is that since you keep a
reference to the queries, they don't close their connection until the
query is actually evaluated. Meaning, if you have more combinations of
(limit, category_id, company_id) than your pool size, you run out of
connections.

Why don't you cache instances instead, by changing:
>        return query.limit(limit)
to
>        return query.limit(limit).all()
?

Hope it helps,
-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to