1 Reply Latest reply on Aug 28, 2012 10:49 AM by an1310

    Distributed counters in Infinispan

    hsn10

      I am looking for best way to implement distributed counters. I need 3 functions:

      • add to counter value (must be as fast as possible - async)
      • query counter value (value obtained may be about 1s old)
      • delete counter

       

      Is there some support for such functionality? I would like to avoid scheme LOCK - increment - RELEASE to get good scalability.

        • 1. Re: Distributed counters in Infinispan
          an1310

          Hi Radim,

           

          I've implemented something similar in my application.  It's actually pretty easy and very performant if you use the distributed executor framework.  Here are some rough guidelines:

           

          • You assuredly will either need a lock/increment/release pattern to get counter values.  However, if you execute a task on the data owner, you're acquiring local locks.
          • You will need to look at the cache configuration options for eager locks.
          • You may want to consider allocating "chunks" of possible counter values for your clients to use locally.  This will reduce contention on the cache, while guaranteeing uniqueness. 
          • (Don't forget about overflow conditions)