the size of the object list to be reconciled and sorted during flush
gets very large - so issue a flush() after every 100 or so entries
added to the session. they'll all execute within the context of the
enclosing transaction.
>
> I found that it seems not the transaction cause the performance
> problem.
> I think it maybe cause by use one session for a long time.
> Performance getting slower with the program run longer time.
> Once I stop the program and run it again, at first it works fast.
>
> So I think it is the problem of using a session for too many query and
> insert?
> I think the identify map or something else getting bigger and bigger
> with time.
>
> Is that correct? How to solve this problem?
Assuming youre on at least version 0.4 with the default settings, the
Session only holds onto objects that are referenced elsewhere in your
application. If your app needs to hold many objects in memory but
you dont want them all being maintained within the Session, remove
them using Session.expunge(someobject) or everything using
Session.expunge_all() (which used to be called Session.clear()). The
flush() process in particular may be scanning the whole collection of
objects.
The 0.5 session has some enhancements such that a flush() usually does
not scan the entire Session's contents.