Andrew
Andrew

Reputation: 177

clustering/replicating counter state with application level scope

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.

Upvotes: 1

Views: 1413

Answers (3)

djna
djna

Reputation: 55957

Some Java EE 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.

Upvotes: 2

Pablojim
Pablojim

Reputation: 8582

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

Upvotes: 1

aperkins
aperkins

Reputation: 13114

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.

Upvotes: 1

Related Questions