Improve performance of hibernate and other things that use DB connections without actually calling the DB via lazy proxy
Description
Environment
Test Plan
Attachments
- 19 May 2008, 11:48 AM
cloned from
Activity
Peter Peterson November 16, 2009 at 10:01 AM
Included in Sakai 2.5.6 per Thomas's script
Aaron Zeckoski August 28, 2008 at 4:32 AM
Verified
Ian Boston August 26, 2008 at 2:00 AM
Applied to K1 and 2.5.x
Ian Boston August 22, 2008 at 1:25 AM
Patch applied to 2.5.x , but conflicts with a an earlier patch on the same area hibernate and datasource, please check that its went in Ok. Will also apply in K1
Ian Boston August 22, 2008 at 1:14 AM
I will commit,
but I have a feeling that we dont have L2 caches enabled in Sakai, so the conection will always be opened whenever the session factory becomes active.
And, there is code in every single request outside Hibernate that access the connection, so it will be opened anyway (in portal, and I think, but I would need to check in the request filter). The only place it might have an impact is if someone enabled L2 caches, and they then configured them to go cluster wide, and they bypassed the sakai request filter.
But, it doesnt look like it does any harm so I will apply it.
One of the Spring masters suggested this to me today. In order to
reduce database load, you put a lazy proxy in between the datasource
and the users (consumers) of it. This means the actual connection is only opened
when it is used and if there are things (like hibernate or some
transactional wrappers) which always open a connection then it does
not waste the connection if the hibernate cache has the value or the
connection is not actually used. This has been around since Spring 1.1 is
highly tested and reliable.
The change would be something like this in
/db-impl/pack/src/webapp/WEB-INF/components.xml (replace the current
bean with the id of javax.sql.DataSource with the two beans below):
<!-- Shared DataSource for all pooled database connections -->
<bean id="javax.sql.TargetDataSource" parent="javax.sql.BaseDataSource" />
<!-- Proxy which will keep only get the connection if one is
actually needed,
this is especially helpful when using hibernate or wrapping
transactions around requests
because it keeps the connection from being opened and held if
it is not needed -->
<bean id="javax.sql.DataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource"><ref
local="javax.sql.TargetDataSource" /></property>
</bean>