Java Reference
In-Depth Information
Once you've written the XML metadata, made the necessary changes to the
domain model classes, implemented the repositories, and written the tests, you
will have a persistent domain model. You will then be able to integrate it with the
presentation tier to create a working application. However, before your applica-
tion goes into production it is quite likely that you will have to improve perfor-
mance by using eager loading and caching.
5.4 JDO performance tuning
A wise software developer once said, “First, make it work, then make it work right,
and finally make it work fast.” The tests that we have written should ensure that it
works right, and so now we turn our attention to how to make it work fast. We saw
in chapter 4 that lazy loading, eager loading, process-level caching, and query
caching are important mechanisms for improving the performance of an applica-
tion that uses an ORM framework. They reduce the load on the database, which is
often the bottleneck in an enterprise application.
It is important to achieve the correct balance between lazy and eager loading.
Lazy loading minimizes the number of objects the application loads from the
database by only loading objects that are actually accessed. Eager loading mini-
mizes the number of trips to the database by retrieving multiple related objects at
a time. By using the right combination of eager and lazy loading, you can often
improve the performance of an application.
Process-level caching is another way to improve the performance of an applica-
tion. It reduces the number of database accesses by caching frequently accessed
objects in memory. Before accessing the database, the JDO implementation first
checks in the process-level cache. Using a process-level cache can often improve
the performance of an application significantly. In this example application, it
makes sense to cache the restaurant-related classes— Restaurant , MenuItem , and
TimeRanges —because they are frequently accessed but rarely updated. An appli-
cation can use a combination of eager loading and process-level caching. How-
ever, relationships from objects that are not cached to those that are should not
be eagerly loaded because that would bypass the cache.
Query caching is an extension of the process-level caching mechanism. The
query cache stores the ID s of the objects returned by a query. When the JDO
implementation is called by the application to execute in the query, it looks in the
query cache before accessing the database. If the query is in the cache, the JDO
implementation then retrieves the objects from the process-level cache. For some
queries in some applications, this can improve performance significantly.
 
 
 
Search WWH ::




Custom Search