It closes the transaction, not the connection (it's ExternalTransaction.close). You fixed that for now by putting everything into a single transaction, but I suppose it will come back to bite you once business logic dictates many small transactions (maybe in a later project, so this may not be relevant for you right now - it's just something to keep in mind). There's no good reason why a getConnection from a connection pool should take up more time than running any SQL statement. Either the connection isn't taken from the connection pool. Which makes me suspect the connection pool isn't active - maybe something is misconfigured. Or Cayenne's getConnection is unreasonably slow. It would be nice to know what actually caused the problem. N.B. writing your own DataSource that reuses connections would be just a reinvention of connection pooling. You don't want to do that - connection pooling is far more involved than meets the eye; doing it well will certainly make you go over the time budget, and doing it not-so-well is a waste of time. (The issues I'm aware of are: keeping connections open in advance to reduce latency, which means opening connections in a separate thread and avoiding race conditions; dealing with connection loss due to networking outages; dealing with connection loss due to server-side time-outs after periods of inactivity; avoiding unnecessary work in a transaction after the connection was gone; distinguishing whether to silently reestablish connection or report back a failed connection, that despends on whether you actually had any SQL activity after establishing the connection. There might be more.) Regards, Jo
________________________________ From: Wernke zur Borg [mailto:[email protected]] Sent: Wednesday, January 25, 2012 10:02 AM To: [email protected] Subject: Re: Performance question To give you a picture here is a screenshot of the profiler showing that one connection is opened and closed for every query. The question I do not understand is why does DataNode.performQueries() unconditionally close the current connection? Otherwise I could probably provide a custom DataSource class overriding getConnection() to re-use connections. Wernke
