1 2 Previous Next 25 Replies Latest reply on Apr 1, 2015 12:21 PM by gaprashanth

    How to set limit on the memory use for Cache

    gaprashanth

      We are planning to use teh EmbeddedCache on the same JVM of our application server ( Weblogic).    The upper limit on the heap will be decided on the server start by using java Xmx arguments. So the question is since both the cache agent and the application server have to share the same heap, how to set an explicit limit on the cache agent so that it always uses its share and does not occupy the entire heap ?

        • 1. How to set limit on the memory use for Cache
          kodadma

          Short answer - you can't (yet).

          • 2. Re: How to set limit on the memory use for Cache
            gaprashanth

            Vladimir, thanks for the reply. 

            So in that case, I was thinking of an alternative. Please find it below.

             

            Infinispan allows setting the maximum number of entries for the named caches. On exceeding the maximum entries, the cache agent would start eviction which removes some entries and makes room for others.

             

            E.g.

             

            Assuming there is 64 GB heap memory is declared by the application server startup command by using java –Xmx, and 32 GB available for caching and there are 5 partitions of cache, then on an average each named cache can declare up to 6GB of maximum size.

            6 GB of memory should be translated into the number of entries to be cached. If each entry (e.g an XPAT H) takes 10KB of data, then the number of entries can be declared as 6,29,145.

             

            So roughly, the cache agent starts cleaning up the named cache on reaching the threshold limit of 6,29,145.  This ensures that the cache agent does not cross its limit on memory at any point of time.

             

            The cache agent cannot determine what is the size required for the cache entries. It depends on the type and volume of the object being cached and varies from application to application. The max memory allocate to the cache is sum of the max size declared on all the named caches.

             

            So basically my point is, setting the max size for the named caches is the only way to limit the size of the cache ?

            • 3. Re: How to set limit on the memory use for Cache
              kodadma

              The question is how to translate number of objects into allocated heap size. You can do it approximately by running your application under jmap (heap explorer).

               

              Btw, I do not think that 64G of heap per Java process is a good idea unless you can tolerate several minutes long GC pauses.

              • 4. Re: How to set limit on the memory use for Cache
                gaprashanth

                Yes, the 64GB was just an example.  Even after running some tools to determine the size of our objects, we can only arrive at some approximate calculations and it can never be accurate as the objects that are cached are of different types and vary in size. 

                 

                I was expecting the Cache technology expose the max size in terms of memory instead of number for the named caches. Later, when the memory size grows beyond a higher water mark of memory, it should automatically evict till the lower water mark is reached.

                Between, is there any feature in pipeline which does something similar ?

                 

                Please have a look at my other post "Important Questions in Infinispan" also, where I have posted some similar questions.

                • 5. How to set limit on the memory use for Cache
                  vblagojevic

                  Prashanth & Vladimir,

                   

                  You are right. At this moment you have to run estimation exercize as you guys did. The eviction algorithms we use, and I am not kidding, are the latest research from academia. We have plans in the pipeline to include eviction based on memory size. We just have not gotten around to it properly and we did not want to do some mediocre patch on top of existing eviction architecture.

                   

                  Regards,

                  Vladimir

                  • 6. Re: How to set limit on the memory use for Cache
                    kodadma

                    Prashanth, stay tuned for the upcoming announce (in June I hope)

                    • 7. How to set limit on the memory use for Cache
                      gaprashanth

                      Thanks for the information. 

                      Yes, we are looking forward for the anouncement as this feature is very imp to us.

                      • 8. How to set limit on the memory use for Cache
                        gaprashanth

                        Guys, continuing that chat,

                         

                        Consider an example where a named cache has declared the max entries as 1000 which is required for storing 2GB of data based on some calculations. But during run-time, assume that the named cache has already consumed 2GB of data for just first 500 cache entries due to the un-anticipated bigger sized objects. But the eviction has not started yet in this situation as the upper limit is still at 1000, so how does Infinispan handle this situation?

                         

                        • If there is additional memory available in the heap, does Infinsipan allows the named cache to use it till 1000 entries are reached ?
                        • If the additional heap memory is not available, what is the behavior of Infinispan in this case? Does it throw an out of memory exception while it continues to add the entries in the cache as the upper limit of 1000 is not reached yet?

                         

                        So I am thinking, is it really good idea to have Infinispan to run as embedded cache and share the JVM with the application server OR to run the Infinispan independently on a remote host and access it using a client-server model, say Hot rod client-server model ?  But what about limitations of Hot Rod client server model w.r.t inability to use the programmatic API.

                         

                        Or is it Infinispan designed for running on smaller heaps on a host but still can acquire a large heap because of GRID ?

                        • 9. Re: How to set limit on the memory use for Cache
                          kodadma

                          Disclaimer: I am not JBoss employee and do not work on Infinispan project.

                           

                          I think you will end up with OOM errors.  Let any Infinispan developer correct me if I am wrong with my assumption.

                          • 10. Re: How to set limit on the memory use for Cache
                            galder.zamarreno

                            Prashanth,

                             

                            As Vladimir said, that scenario would lead to an OOME.

                             

                            The limitations that are in the Hot Rod server not allowing programmatic definition of caches have a good reason, and that's the fact that asymmetric clusters are not supported. In fairness, even though programmatic cache definition is allowed in embedded caches, you could still have the same issue unless all your caches are defined on startup. More info on asymmetric clusters problem in https://issues.jboss.org/browse/ISPN-658

                             

                            So, bottom line is that if you think that Infinispan will have a negative impact on your app jvm behaivoiur, use remote access to Hot Rod server. And regardless of whether you use embedded or remote caches, make sure all your caches that you'll use are defined and started before you start accepting requests.

                            • 11. Re: How to set limit on the memory use for Cache
                              gaprashanth

                              Hi Galder,

                               

                              We are very much keen on programmatically creating the cache definitions. Infact, we dont keep anything on the Infinispan configuration files and all the named caches would be created during the startup of the cache also at the same on on all the nodes N1, N2 and N3. I guess the startup is working for us.

                               

                              Now coming to the runtime changes to the configurations on the different nodes, we are planning to do the same programmatic config changes simulataneously on all the nodes to avoid any assymmetry. For e.g., assume N1, N2, N3 initially had C1, C2 and during runtime C3 is added simulataneouly (almost) on all the nodes.

                               

                               

                               

                              Whats you opinion on this approach. But there can be some small differnce in the timing of this parallel config change. Does this cause any impact and resulting in the same issues as mentioned above in the thread ? 

                               

                              Consider a situation, if C3 is added on N1 and if updates happen to C3 on N1 just slightly before it is parallely added on N2 and N3, does it cause any issues ?

                               

                               

                              • 12. Re: How to set limit on the memory use for Cache
                                mircea.markus

                                This is the JIRA for supporting memory size based eviction: https://issues.jboss.org/browse/ISPN-863

                                Feel free to vote for it.

                                • 13. Re: How to set limit on the memory use for Cache
                                  gaprashanth

                                  The JIRA issue is pretty much similar to the core issue raised here. But the original question still remains unanswered. The situation is, if we get OOME well ahead of reaching the Max entries for a named cache, then is it a case of cache hanging? Because, this wont even trigger the eviction as the max entries still not reached and also the cache can not be used untill some memory is freed.

                                   

                                  So what does Infinispan recommend to recover from such a situation. One option would be to manually and randomly  invoke the evict() on some of the cached entries. But are there any better methods ? Please suggest.

                                  • 14. Re: How to set limit on the memory use for Cache
                                    mircea.markus

                                    So what does Infinispan recommend to recover from such a situation. One option would be to manually and randomly  invoke the evict() on some of the cached entries. But are there any better methods ? Please suggest.

                                         That would work. Indeed the better approach would be once ISPN-863 is in place.

                                    1 2 Previous Next