Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-6889

replyWaitMaxTime stat calculation code needs improvement

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.10.0
    • core

    Description

      The way the replyWaitMaxTime is calculated has some problems:
      1. the elapsed time is calculated using System.currentTimeMillis but should instead use getStatTime (it actually uses getStatTime for the begin timestamp but not for the end timestamp).
      2. a local atomic should be used to calculate it instead of reading the value from the Statistics instance. Reading is expensive since it uses synchronization.

      The following is a prototype fix for #2 I used when performance testing:

      diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionStats.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionStats.java
      index 91c47e2495..d591e35570 100644
      --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionStats.java
      +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionStats.java
      @@ -14,6 +14,8 @@
        */
       package org.apache.geode.distributed.internal;
       
      +import java.util.concurrent.atomic.AtomicLong;
      +
       import org.apache.logging.log4j.Logger;
       
       import org.apache.geode.StatisticDescriptor;
      @@ -1602,6 +1604,8 @@ public class DistributionStats implements DMStats {
           return getStatTime();
         }
       
      +  private final AtomicLong replyWaitMaxTime = new AtomicLong();
      +
         @Override
         public void endReplyWait(long startNanos, long initTime) {
           if (enableClockStats) {
      @@ -1610,8 +1614,17 @@ public class DistributionStats implements DMStats {
           }
           if (initTime != 0) {
             long mswait = System.currentTimeMillis() - initTime;
      -      if (mswait > getReplyWaitMaxTime()) {
      -        stats.setLong(replyWaitMaxTimeId, mswait);
      +      boolean done = false;
      +      while (!done) {
      +        long currentReplyWaitMaxTime = replyWaitMaxTime.get();
      +        if (mswait > currentReplyWaitMaxTime) {
      +          done = replyWaitMaxTime.compareAndSet(currentReplyWaitMaxTime, mswait);
      +          if (done) {
      +            stats.setLong(replyWaitMaxTimeId, mswait);
      +          }
      +        } else {
      +          done = true;
      +        }
             }
           }
           stats.incInt(replyWaitsInProgressId, -1);

      Attachments

        Issue Links

          Activity

            People

              mboxwala Murtuza Boxwala
              dschneider Darrel Schneider
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 4h 40m
                  4h 40m