5 Replies Latest reply on May 10, 2019 10:29 AM by pferraro

    Caching in WildFly

    valsaraj007

      When we load a page that has complex queries, it takes a lot of time for the first time after WildFly server restart. But after the first time, it loads faster. Even if the different user accessed the page, there is no delay. But after some hours elapsed, again feels the same delay and after the delay, subsequent access works faster. We have second level caching attribute as ENABLE_SELECTIVE and not enabled cache for these queries. We are using JPA over hibernate in WildFly. So what may be impacting for faster response and why the delay comes after hours even if server not restarted? Also we have prepapred statement cache enabled and it's set to 100.

        • 1. Re: Caching in WildFly
          pferraro

          Take a look at the cache expiration configuration of the various cache regions of your second-level cache.  I would guess that your expiration configuration does not match your expectations.

          1 of 1 people found this helpful
          • 2. Re: Caching in WildFly
            valsaraj007

            pferraro Thanks!

            The default settings with WildFly is used without much changes. There is no other cache regions added.

            <cache-container name="hibernate" default-cache="local-query" module="org.hibernate">

                                <transport lock-timeout="120000"/>

                                <local-cache name="local-query">

                                    <locking isolation="READ_COMMITTED"/>

                                    <transaction mode="NONE" locking="OPTIMISTIC"/>

                                    <eviction strategy="LRU" max-entries="10000"/>

                                    <expiration max-idle="100000"/>

                                </local-cache>

                                <invalidation-cache name="entity" mode="SYNC">

                                    <locking isolation="READ_COMMITTED"/>

                                    <transaction mode="NON_XA" locking="OPTIMISTIC"/>

                                    <eviction strategy="LRU" max-entries="10000"/>

                                    <expiration max-idle="100000"/>

                                </invalidation-cache>

                                <replicated-cache name="timestamps" mode="ASYNC">

                                    <locking isolation="READ_COMMITTED"/>

                                    <transaction mode="NONE" locking="OPTIMISTIC"/>

                                    <eviction strategy="NONE"/>

                                </replicated-cache>

                            </cache-container>

            Currently in 2 hours he same lag occurred when tested. Which settings need to be adjusted to control cache expiration?

             

            Here is the L2C metrics printed during the operation:

            [Server:ltchie-node-00] 20:24:59,495 INFO  [org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-8) Session Metrics {

            [Server:ltchie-node-00]     15330440 nanoseconds spent acquiring 48 JDBC connections;

            [Server:ltchie-node-00]     4266808 nanoseconds spent releasing 48 JDBC connections;

            [Server:ltchie-node-00]     16230818 nanoseconds spent preparing 48 JDBC statements;

            [Server:ltchie-node-00]     47383156 nanoseconds spent executing 48 JDBC statements;

            [Server:ltchie-node-00]     0 nanoseconds spent executing 0 JDBC batches;

            [Server:ltchie-node-00]     96615 nanoseconds spent performing 1 L2C puts;

            [Server:ltchie-node-00]     1512024 nanoseconds spent performing 28 L2C hits;

            [Server:ltchie-node-00]     1162267 nanoseconds spent performing 28 L2C misses;

            [Server:ltchie-node-00]     913458 nanoseconds spent executing 1 flushes (flushing a total of 52 entities and 228 collections);

            [Server:ltchie-node-00]     15298375 nanoseconds spent executing 31 partial-flushes (flushing a total of 712 entities and 712 collections)

            [Server:ltchie-node-00] }

            • 3. Re: Caching in WildFly
              pferraro

              So, according to your configuration, queries, entities, and collections will only be retained in memory for 100 seconds, unless accessed.  Does this match your expectations?

              1 of 1 people found this helpful
              • 4. Re: Caching in WildFly
                valsaraj007

                No, I think it should be higher. So the existence of an entry in local hibernate cache depends on  max-entries & max-idle.

                • 5. Re: Caching in WildFly
                  pferraro

                  Correct.