views:

193

answers:

3

I need to replicate a sequence/counter across an eight node cluster. This means that each http request receives the next value in the sequence by calling something like getNextIntAndIncrement(), where the sequence state is synchronized across all servers. To clarify, this must exist at application/global scope, not session. I know it sounds like an awful idea and will undoubtably lead to bottlenecking but this is the requirement.

My question is what is the best solution? I've looked at stateful session beans, but they appear to be designed for only one client. I considered a database sequence. I've also looked at Terracotta clustering; they have a sequence demo http://www.terracotta.org/web/display/orgsite/Recipe?recipe=sequencer However I'd like to avoid third party solutions if a J2EE solution exists. I'm using Weblogic 8.1.

+1  A: 

I think a database sequence would likely give you the most deterministic result, especially if you use highly-serialized transactions to request it.

However, I would seriously question the validity of doing something like this, but that is just my 2 cents.

aperkins
+1  A: 

some JEE vendors have distrubted cache solutions (eg. WebSphere's Object Grid) asnd you've already identifed 3rd party offerings but I don't believe a portable standard exists.

What's wrong with the DB solution? It's clear that locking is going to be needed, so why not leave to the DB. My guess is that if you really need true incremental values, no values missed etc. then transactional relationships with other database values will be important, so use the DB.

If you can relax the need for absolute sequenetial values (ie. allow gaps) then you can parcel out sets of numbers and thereby greatly reduce contention. If you truly need sequential values, no gaps, then you are buying into the need for some degree of locking between the instances - you can't allow a second "thread" to get a new sequence number until you "commit" the use of the current one. If you can afford to lose the odd sequence number then you do much better. Or if you can independent numbering schemes between instances you are in a much better positions. For example name you servers a, b, c ... have ids a001, a002, b001, c001, c002 etc.

djna
I'm going to pursue a database solution. thanks
Andrew
A: 

You have weblogic in the tags for this question - Weblogic allows cluster singletons. e.g. one instance per cluster with failover support.

This should fulfil your requirement:

http://e-docs.bea.com/wls/docs100/javadocs/weblogic/cluster/singleton/SingletonService.html

Pablojim
I don't (yet) understand how this helps.1). How does the HttpRequest processor in one server access the count being maintained in the Singleton Service? 2). If the Singleton instance (or its server) should fail, how is the count maintained? In a DB or by some other mechanism?
djna
thanks for suggestion but we are using weblogic 8.1
Andrew