Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate efficiency issue ...

 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible to tell (through Hibernate) that a given Session is heavy loaded, i mean, if the table size was big and stuff like that ?

Actually what I'm trying to do is to balance reading from multiple database instances so that if one was heave loaded, then i can handle that in some way.

Any comments are welcomed ...

Thanks in advance ...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you worried about the memory footprint a particular session has? Getting access to memory details of anything in Java is very difficult. You could use an Interceptor to interact with your Session, but I'm not sure what you could actually do to prevent this. Assuming you can define what you mean by "heavily loaded" through some metric you maintain you could possibly flag to whatever logic provides your multiple SessionFactories to redirect new requests to a different SessionFactory?

The normal approach to this would be to deploy your application in an application server or a framework like Spring, so it is easy to scale once you've profiled your application's behaviour.

Another approach could be to use a Session per request and prevent your database loading whatever you've defined as too much data via whatever database specific routes.

A long shot might be to provide your own Session implementation that eveicts objects once your metric has been hit. This won't swap the swap the DataSource, but could mean you can control your session load a bit more (assuming again of course that you can define a suitable metric). Alternatively your bespoke implementation could throw an exception on get or load requests when this metric has been hit and whatever logic provides your multiple SessionFactories could reservice the request from another SF?
[ December 11, 2007: Message edited by: Paul Sturrock ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic