views:

64

answers:

4

I'm using Hibernate to work on a new project, and as I work I'm realizing that my original vision for the application may not end up being its destiny. Data that I think is not going to be often requested (and thus lazy-loaded) might end up being needed for 85% of requests. Conversely, data that I'm loading under the assumption it will be needed might turn out to not be needed as often as I think it will.

Is there some profiling tool or method of analyzing ORM usage (specifically: Hibernate) that can help me tune my application after it has reached critical mass?

The only thing that comes to mind is to write some Selenium scripts that mimic actual usage and do load testing with different configurations. That seems like it might work but also feels like a very round-about way of getting the information I'm after. There has to be a better way...

A: 

Use the SQL profiler/logger of your database to keep tabs of your production database. Keep a lookout for lazy-loading queries or often repeated queries which may indicate a N+1 problem (iterating over a lazy collection, loading each object individually).

I'm not aware of a (any) ORM which provides such capability.

David Schmitt
+1  A: 

Is there some profiling tool or method of analyzing ORM usage (specifically: Hibernate) that can help me tune my application after it has reached critical mass?

Hibernate 3 gather statistics at run-time. Might be worth having a look. There is a section "Monitoring performance" in the hibernate doc.

The only thing that comes to mind is to write some Selenium scripts that mimic actual usage and do load testing with configurations. That seems like it might work but also feels like a very round-about way of getting the information I'm after.

You should try first to capture some real workload. Then figure out how to reproduce it.

Otherwise you will still be biased and may generate a load that actually doesn't represent the reality anyway. If you can't capture a real workload, then discuss with potential end-user to see how they use the app and make sure your scenario are as close as possible to the real end-user behavior.

ewernli
+1  A: 

"...help me tune my application after it has reached critical mass?"

This is important.

You're tuning your application -- as a whole. App + data base structure + Hibernate ORM mappings + anything else.

Your application should have logs that you can use for tuning your application. If you don't have suitable logging, now is the time to add an appropriate set of logs to determine which use cases are being used and what's happening.

Tuning logs are as important as debugging logs. And they're a first-class part of your application.

S.Lott
+1  A: 

The Hibernate Profiler can generate live reports from hibernate's run time statistics. Various alerts are generated, such as warning about SELECT N+1.

It can be used in a Continuous Integration system.

Lachlan Roche