문제

I'm using z3c.saconfig to configure sqlalchemy in a Plone/Zope application. In this application, we created a Session sqlalchemy with named_scoped_session("dbmyapp") z3c.saconfig method. The Session is created and works very well. But we created just one Session for the app.

Can this [one Session sqlalchemy / app] be a bottleneck for app?

By the way, can we create more than one Session per app? Are there any advantages?

snippet of buildout.cfg:

<configure xmlns="http://namespaces.zope.org/zope"
    xmlns:db="http://namespaces.zope.org/db">
    <include package="z3c.saconfig" file="meta.zcml" />

    <db:engine name="dbmyapp" url="oracle://user:pass@hostname:port/sid" />
    <db:session name="dbmyapp" engine="dbmyapp" />
</configure>
도움이 되었습니까?

해결책

The session machinery takes care of providing you with one connection per thread; since you can only execute sequential code within one thread that connection cannot become a bottleneck.

Different parts of the code can request their own session; the session machinery will reuse session connections as required. This is not something you generally have to worry about, that's all handled for you by z3c.saconfig and its dependencies.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top