13 Replies Latest reply on May 22, 2008 8:57 AM by beep_beep

    Memory management: questions

    beep_beep

      Hi!

      While I have good inspiration, reading about Jboss cache, I still have a "leakage doubts".

      Memory consumed by the cache is not under absolute control - that worries me.

      I have several questions:
      1. Is it possible to rewrite maps to be kinda Soft Reference in Jboss cache? Do you have Soft/Weak Reference already implemented?
      2. Is it possible to create eviction policies based on actual memory consumption? How hard is it?
      3. What is optimal(less risky) algorithm(approach) to "figure out" right eviction policies to avoid OOM error?

      Thanks a lots!


        • 1. Re: Memory management: questions
          manik

          1. Regarding soft references in the cache, again this isn't something that people have asked for; you're the first. Feel free to raise a JIRA for it.

          2. There is no memory-based eviction policy yet (see JBCACHE-11). Have a look, vote for it, and if you have the time maybe even contribute an implementation! :-)

          3. Your best bet is to use an LFU or LRU policy, fixed to a number of nodes in memory. If you know what you put in each node and how much memory (approximately) each object consumes, you can "estimate" what your maxNodes value should be for your region.

          • 2. Re: Memory management: questions
            beep_beep

            Thanks Manik!

            Good idea to contribute that memory eviction... I should think about it.

            I have another question.

            Why once I've started use OptimisticLocking(with transaction manager), hits statistics are always 0. Puts and Miss counter grows, but hits are always 0.
            Can you explain?

            Thank you.

            • 3. Re: Memory management: questions
              manik

              No idea - try enabling your logs and see if all your invocations actually result in cache misses?

              • 4. Re: Memory management: questions
                beep_beep

                I've noticed in log:
                05-22@11:53:31 INFO (OptimisticNodeInterceptor.java:103) - CRUD Method _put(GlobalTransaction:<172.16.194.121:2104>:6, /test/web/TestEntity/test.web.TestEntity#5, item, {_subclass=test.web.TestEntity, _version=null, name=name-4, _lazyPropertiesUnfetched=true}, true, 0) called - don't know how to handle!

                It probably needs a version field?

                I do not know what is the problem...

                • 5. Re: Memory management: questions
                  manik

                  What version of JBC is this?

                  • 6. Re: Memory management: questions
                    beep_beep

                    1.3-pre-alpha

                    But it's the one shipped with last hibernate.

                    When I tried to use newest JBC, hibernate complained, that it can't find a class , something like "../cache/" when JBC has this class under ../transaction/cache...

                    some change in package name and no integration anymore...

                    • 7. Re: Memory management: questions
                      beep_beep

                      java.lang.NoClassDefFoundError: org/jboss/cache/TransactionManagerLookup
                      at java.lang.Class.getDeclaredConstructors0(Native Method)
                      at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
                      at java.lang.Class.getConstructor0(Class.java:2671)
                      at java.lang.Class.newInstance0(Class.java:321)
                      at java.lang.Class.newInstance(Class.java:303)
                      at org.hibernate.cfg.SettingsFactory.createCacheProvider(SettingsFactory.java:375)

                      • 8. Re: Memory management: questions
                        manik

                        Use the latest 1.4.X release. I wouldn't recommend using alpha software, much less pre-alpha! :-)

                        JBC 2.x will only be compatible with Hibernate 3.3.x which hasn't been released yet.

                        • 9. Re: Memory management: questions
                          beep_beep

                          Great!
                          But after that installation I have an error:
                          org.hibernate.cache.CacheException: java.lang.UnsupportedOperationException: putFailFast() is not supported with Optimistic Locking
                          org.hibernate.cache.TreeCache.put(TreeCache.java:81)
                          org.hibernate.cache.TransactionalCache.put(TransactionalCache.java:58)
                          org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:156)
                          org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)

                          Have any idea?

                          Thanks!!

                          • 10. Re: Memory management: questions
                            manik

                            Have you seen http://wiki.jboss.org/wiki/JBossCacheHibernate?

                            "From the wiki:" wrote:

                            If you are using OPTIMISTIC locking, make sure you use the OptimisticTreeCacheProvider that ships with Hibernate 3.2.x and higher.




                            • 11. Re: Memory management: questions
                              beep_beep

                              I see, where you throw that exception, seems you have reasons for that.
                              But why hibernate use that putFailFast I do not know...
                              Seems Optimistic locking is gone for me...

                              • 12. Re: Memory management: questions
                                beep_beep

                                We sent messages in the same time!
                                Thanks Manik!
                                I appreciate your help so much!!! Peter.

                                • 13. Re: Memory management: questions
                                  beep_beep

                                  One more thanks!!!!!

                                  Optimistic works. I use JBC 1.4 SP9.