On 13/12/2012, at 11:07 PM, Jim Fulton <j...@zope.com> wrote:
On Wed, Dec 12, 2012 at 6:31 PM, Dylan Jay <d...@pretaweb.com> wrote:
I've been working with zope for over 12 years and something that
keeps coming up is sacling IO bound operations in Zope. The typical
example is where you build an app that calls external apis. While
this is happening a zope thread isn't doing any other processing
and because there is a 1 thread 1 zodb cache limit. You can run
into scalability problems as you can only have as many threads your
RAM / average cache size. The end result is low throughput while
still having low CPU. I've consulted on some $$$ sites where others
have made this mistake. It's an easy mistake to make as SQL/PHP
systems don't tend to have this limitation so new developers to
zope often don't to think of it.
I was listening to a talk by a Java guy on Friday where he warned that
a common newbie mistake was to have too large a database connection
pool, causing lots of RAM usage. I expect though that ZODB caches,
consisting of live Python objects exacerbate this effect.
The possible workarounds aren't
pretty. You can segregate your api calling requests to zeo clients
with large numbers of threads with small caches using some fancy
load balancing rules. You can rework that part of your application
to not use zope, perhaps using edge side includes to make it seem p
art of the same app.
Feel free to shoot down the following makes no sense. What if two
or more threads could share a zodb cache up until the point at which
one wants to write. This is the point at which you can't share a
cache in a consistent manner in my understanding. At that point the
transaction could be blocked until other readonly transactions had
finished and continue by itself? or perhaps the write transaction
could be aborted and restarted with a special flag to ensure it was
processed with the cache to itself. As long as requests which
involve external access are readonly with regard to zope then this
would improve throughput. This might seem an edge case but consider
where you want to integrate an external app into a zope or Plone
app. Often the external api is doing the writing not the zope
part. For example clicking a button on a plone site to make plone
send a tweet. It might also improve throughput on zope requests
which involve zodb cache misses as they are also IO bound.
A simpler approach might be to manage connections better at the
application level so you don't need so many of them. If you're goinng
to spend a lot of time blocked waiting on some external service, why
not close the database connection and reopen it when you need
it? Then you could have a lot more threads than database connections.
I'd never considered that the cache was attached to the db connection
rather than the thread. I just reread
http://docs.zope.org/zope2/zope2book/MaintainingZope.html and it says
So what your saying is I'd tune db connections down to memory size on an
instance dedicated to io bound and then increase the threads. Whenever a
thread requests a db connection and there isn't one available it will
block. So I just optimize my app the release the db connection when not
In fact I could tune all my copes this way since a zone with 10 threads and
2 connections is going to end up queuing requests the same as 2 threads and
This should be easier to achieve and changes the application less than the
erp5 background task solution mentioned.
It's possible that ZODB could help at the savepoint level. For
example, maybe you could somehow allow savepoints to be used accross
tranasctions and connections. This would be a lot saner that tring to
share a cache accross threads.
I can see from the previous post, as there is no checkout semantics in
zodb, you are free to write anytime so there is no sane way to block at the
point someone wants to write to an object, so it wouldn't work.
You perhaps could have a single read only db connection which is shared? So
in the case above during io bound operations or if you knew you never want
to write, you could close the normal connection and open a read only one.
Jerky is better than bacon! http://zo.pe/Kqm
For more information about ZODB, see http://zodb.org/
ZODB-Dev mailing list - ZODB-Dev@zope.org