TopLink Wiki
Main
RecentChanges
Set your name in
UserPreferences
Referenced by
JSPWiki v2.0.52
|
Built For Speed
Refer to the TopLink Performance chapter in TopLinkDocumentation for hints on improving performance. forum:277548 Some basic things to consider are:
To assess/diagnose performance problems, the SessionConsole can be used -- now replaced by the TopLinkWebClient.
Data Integrity
Optimistic LockingSee TopLinkLocking.
Client Session vs. Server Session?The server session is acquired from the SessionManager?. A client session is acquired with ServerSession?.acquireClientSession.
Reading from the database
Reading moreJoining: for 1-1 relationships, the attribute is joined to and read with the main object in one query. Especially good for back pointers! Warning: joining always does an inner join => can miss valid objects if the attribute doesn't exist. Batch reading: read all objects at once in a 1-* relationship. Batch reading on 1-1 relationships means the target will be batch read when a ReadAllQuery is run for the parent object (less useful). Beware of cascading joined/batch read attributes! Can generate a lot of queries.
Reading lessIndirection: don't load the referred object until asked for it. 1-* relationships can be transparent (collections), use ValueHolder for 1-1 relationships. Partial read: read parts of an object instead of the whole object at once. Beware of primary key issues.
Reading from the session vs. reading from the UOWThe UOW registers any object read through it. This causes the UOW to do extra work when writing and merging UOWs. Objects read through the session do not incur this extra cost -- but they cannot be part of a write.
Bypass cache on readIt is possible to disable the cache on specific read queries. E.g. when the objects are only shown once, and don't need to be copied into the cache.
Cursored streamsRead objects using a cursored stream instead of getting a huge collection that will have to fit in memory.
In-memory QueriesLeverage the cache as much as possible. E.g. all non-primary key queries always go to the database by default! Set checkCacheThenDatabase on specific read object queries to prevent this. Toplink architect gives rule of thumb for optimization: Regular in-VM call = 1, EJB (remote) call = 10, database call = 100.
Increase cache sizesKeep some recurrent items in memory at all times by changing the map type to FullIdentityMap and increasing the cache size.
ProfilingThe ToplinkSessionConsole? can be used to observe the cache, run queries, etc.
Write Queries
Read-only classes/descriptorsRead-only classes aren't made part of the merge done by the UOW after committing. See javadoc:Descriptor#setReadOnly(): Declaring a descriptor is read-only means that instances of the reference class will never be modified. Read-only descriptor is usually used in the unit of work to gain porformance as there is no need for the registration, clone and merge for the read-only classes. I've found this on the TopLink discussion forums at Oracle: Marking a relationship as read-only indicates that the relationship should not be used in the creation of the source object's row for writing. It does not mean that the target class (in this case Error) is read-only. Read-only classes must be set on the project (globally) or on the UnitOfWork (per transaction). Read-only mappings are typicaly used where multiple mappings provide te same value. EXAMPLE: The FK of a 1:1 is mapped as a direct-to-field as well as being in the 1:1 relationship mapping. Since they would both result in populating the source object's FK field one of them must be selected to be read-only.
Read objects through session instead of UOWSee above; objects read through a UOW are automatically registered and subjected to the write/merge computation done by the UOW.
Optimize UOW mergeInstead of using deepMergeClone (the most expensive merge option), consider merging objects manually using finer-grained methods. See MergeCloneAPI.
Batch writingAllows the JDBC driver to batch queries into a single DB call.
Statement binding and cachingToplink can prepare and cache statements. My tests show a 40% improvement on simple objects.
Preparing/caching Toplink queriesToplink queries can be prepared and cached just like JDBC statements.
Bypass cache on writeWhen the changes made to an object don't need to be merged into the cache, the cache can be disabled on specific write queries.
See AlsoConformResultsInUnitOfWork, TopLinkDocumentation, PreparedStatementCaching
|
||||||