3 Replies Latest reply on Nov 14, 2005 8:57 AM by Bela Ban

    Decoupling disk writes

    Dan G Newbie

      Hi--

      I'm thinking of using JBossCache in a large project and I've been reading the docs, but I'm not totally clear about some aspects. I appologize for the really basic questions, but I was hoping someone might know, since it would help me choose whether to use JBossCache.

      I've got a Map that's tracking how many times certain things are accessed in order to do some statistics. So, I've got a map of key -> long where I'll be incrementing the value extremely often. I want the current values to persist between sessions, but if on a major error or shutdown, I lost a few updates, it's not the end of the world (likewise, if I few machines in a cluster occasionally step on each other and I lose an increment, it's not a crisis).

      So, I know that I want to use JBossCache and have it occasionally write updates to disk. I assume a CacheLoader is the right way to go. Here are my questions:

      1) Does this decouple cache reads from saving to disk? So, I can do an update and the main thread of my program containues without waiting for the update to disk. (I've been prototyping using a SQL database, and waiting for writes to happen before continuing makes my system unusable).

      2) Does it write every for update, or can it batch changes? I'd love it if I could say "Only write changed values every 5 minutes".

      3) If the above are doable, can they be done with the exisiting CacheLoaders, or would I need to write a custom one?

      and a free bonus question:

      4) Is there any way to make things more memory-efficient if I'm mapping long->long.

      Thank you very much for your help,
      Dan

        • 1. Re: Decoupling disk writes
          Bela Ban Master

          Use an AsyncCacheLoader as facade, as described in the documentation (jboss.com/products/jbosscache)

          • 2. Re: Decoupling disk writes
            Dan G Newbie

            Thank you Bela--I missed that. I assume it will still write each update separately rather than merging them, correct?

            (If so, I may write a version that delays and merges updates cases like mine where updates to different keys are idempotent. I've never looked at the JBossCache, so hopefully it won't be too hard, though I probably won't get around to it for a month or so. If so, I'll contribute it back...)

            Thanks again,
            Dan

            • 3. Re: Decoupling disk writes
              Bela Ban Master

              Yes, it will write each update separately. This can be mitigated, however, by enabling update queueing in the TreeCache itself.
              ahem, now, this is not true. Sorry, it would still write individual updates to disk