Showing posts with label Performance. Show all posts
Showing posts with label Performance. Show all posts

2010/03/15

Improvement on Hibernate Query Cache

Cache improves performance by transparently storing data such that future requests for that data can be served faster. Hibernate offers a session scope transactional cache which spans the scope of the session. Hibernate also offers a configurable secondary level cache which spans across multiple sessions. Clustered/Distributed Caches can be configured so that it can be accessed across the entire application server cluster.

Hibernate secondary cache offers pretty good entity cache. Entity cache speeds up entity loading by its primary key. For instance:

select c from Cat c where c.id = :id

It supports query cache too, to enable query cache, you'll need to specify the hibernate property:

hibernate.cache.use_query_cache true

Query cache caches Query result sets, so the cache can provide you an answer for the queries like:

select p from Person p where p.sin = :sin

Let's say, the SIN of a person is never gonna change, so cache the above query will be useful.

Hibernate provides 'natural id' based on queries which can effectively solve the above problem. However, there are many other queries that hibernate cannot handle effectively. For instance, if we want to find all contact information (phone numbers only) for a person:

select pn from PhoneNumbers pn where pn.person.id = :pid 


The primary problem for Query caches, is that hibernate will completely invalidated by any modification to the underlying table, even on entities that's totally unrelated to the query. In the above example, any insertion/update/deletion to the telephone table, on any record, will completely wipe out the entire cache for the above query.

There needs to be a 'smart query cache' to solve this problem. Fortunately, this can be done by providing custom query cache, and we can then refreshes them by listening on hibernate 'entity modification' events. The listener will allow us to intercept any insertion/update/deletion to any telephone record, and then we can determine to only refresh the affected query cache.

2008/04/20

10 Ways to use Hibernate Effectively, by Brian Sam Bodden

Brian Sam Bodden on the Seattle NFJS Java Conference. 


- Inheritance, Table per Concrete Class, Table per Class Hierarchy, Table per Subclass
- Identify and use Components in the Mapping
- Dynamic Data Filtering can be enabled in either HBM file or use Annotation
- While generated SQL is good enough in most case, Hibernate does support Customer SQL as well as native SQL with direct JDBC connection. iBATIS alike but you only require to customize the SQL when needed.
- Bulk Operations - Enable JDBC Batching & Be mindful of Session and 2nd Level Cache
- Cache - Session Cache & 2nd Level Cache, Read-Only, Read/Write & Query Cache
- Terracotta - Claims of performance gains in the range of 2-4x when integrating with second level cache
- Hibernate Search - Free text search with Lucene, Annotation driven, luceneQuery = parser.parse("name:beckham or name:galaxy")
- Profiling/Debugging - beware of the Write behind fact of Hibernate. p6spy, Jahia's SQL Profiler, Hibernate Statistics
- Hibernate/Jboss Tools - http://www.hibernate.org/255.html
- Hibernate Tips & Tricks Page: http://www.hibernate.org/118.html

2007/10/24

Java Performance - ALL Tips

Oh yes, this is a complete list of ALL Java perfomance tips. Thanks for www.javaperformancetuning.com

http://www.javaperformancetuning.com/tips/rawtips.shtml

2007/10/17

IntelliJ IDEA Performance

There're some concerns about IntelliJ IDEA Performance. And here is the tips that I used to make mine run fast. Some of them come from my own experience, some of them come from the know-everything internet.

  • Make sure you have all your libraries on your local harddrive (as opposed to mounted network drive). After I moved all my libraries from a network drive to local harddrive, the time for a 'make' on the project is reduced from around 60 seconds to just 5-7 seconds!
  • Defragment your Disk and reboot your computer. IDEA creates lots of small files and too much fragmentation is a nightmare.
  • Turn off Anti Virus completely. Yes I mean completely. It affects the performance dramatically.
  • Turning off Local History or even reducing the number of history days improved the performance significantly.
  • Adjust VM settings. Here is my idea.exe.vmoptions file (on windows):
-Xms512m
-Xmx512m
-XX:MaxPermSize=99m
-ea

Change it as you see fit per your hardware configuration.

More information is available at http://blogs.jetbrains.com/idea/2006/04/configuring-intellij-idea-vm-options/.
  • The Debugger in IDEA may work slowly if the Force classic VM option is not selected in the File Project Properties Debugger dialog. Using Method Breakpoints may also slow down the debugging process. I had two breakpoints on the method name instead of the first line of the method. It was taking a half hour to get to the breakpoint Changing these to line breakpoints gave me two orders of magniture
  • You may notice IDEA hang for several seconds when you switch to it from other applicationDisable Settings General Synchronize files on frame activation.
  • Disable windows paging file if you have enough memory. Get more memory if you don't have enough. Swapping is a performance nightmare.
  • Turn off windows indexing services, either set it to Disabled or Manual unless you do lots of file system search (even you do, I recommend Google Desktop Search). IDEA use lots of small files so background indexing can have a big negative effect on it's performance.
  • Control Panel/System/Properties/Advanced/Visual Effcts, Adjust for best performance. Unless you're willing to sacrify performance for visual effects like windows animation, fading/sliding etc.

Well well... why another J2EE blog? I benefited from other people's technical blogs, and guess what, it's a good idea to contribute some of my works too. Hope it's helpful and useful, to all of your folks.