-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: second-level cache in a cluster - locking?
PostPosted: Wed Dec 19, 2007 5:13 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 5:11 pm
Posts: 32
Location: Toronto
Does anyone have any experience using a second-level cache in a cluster?

In the docs section about the second-level cache, under read/write strategy, it says:

Quote:
If you wish to use this strategy in a cluster, you should ensure that the underlying cache implementation supports locking. The built-in cache providers do not.


Can anyone shed more light on this? Specifically:

1. Why is locking required in a cluster but not in a single process?
2. Why don't the built-in cache providers support locking? Is it particularly difficult to implement? Are there significant performance penalties?

A possible means of implementing locking is suggested here (in reference to memcached): http://www.socialtext.net/memcached/index.cgi?faq#managing_a_memcached_cluster

(see section "Emulating locking with the add command")


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 11:30 am 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
The answer to question 1 is because only one mutable instance of the object exists on a single server. Where multiple mutable instances exist in a cluster. Thus you have to keep the objects synchronized.

I don't know the answer to question 2. I'd imagine locking objects across servers is more difficult and more resource intensive than using a solution like memcached. Memcached only stores one copy of the object across the farm so no locking is needed. Think of memcached is being a single big out of process hashtable spread across servers.

If you want to use nhibernate across a server farm or cluster you have these options.
1. Turn 2nd level caching off
2. Use a third party cache provider that supports farms/clusters
3. Use memcached with the built in NHibernate memcached provider.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 2:45 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 5:11 pm
Posts: 32
Location: Toronto
Thanks for responding peterlemonjello. I see what you mean about the need to keep objects in sync if multiple instances exist in the cluster. However, are you sure that's the whole story? I spent some time sifting through the NH source in the Cache namespace, and although I can't make sense of all the details, it seems that the lock/unlock methods are used by the concurrency strategy to ensure proper transaction isolation. That's why it doesn't make sense to me that these methods are not implemented even for an in-process cache (eg SysCache). However, no one else seems bothered by this... I would just like to understand why...

Ultimately I would like to use memcached, but I need a better understanding of how its use will or will not affect transaction isolation. Do you know if there any issues to be aware of in this regard?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 5:20 pm 
Beginner
Beginner

Joined: Wed Jul 19, 2006 8:24 am
Posts: 35
I'm not sure that's the whole story. I guess I kind of took a leap of faith after spending a lot of time reading about the 2nd level cache on the forums. I haven't spent much time looking at the code. I've just assumed it'll do what it's designed to do until a problem arises.

FWIW, we used to use a server farm with Syscache2 and sqlcache dependancies to deal with cache synchronization without any problems. We've since transitioned to memcached. So far we haven't had any transaction isolation problems. In fact it was a pretty simple migration to memcached.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 5:35 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 5:11 pm
Posts: 32
Location: Toronto
Good to know - Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.