dschneider-pivotal commented on a change in pull request #7358:
URL: https://github.com/apache/geode/pull/7358#discussion_r806060692



##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/statistics/RedisStats.java
##########
@@ -37,23 +38,29 @@
   private final AtomicLong keyspaceMisses = new AtomicLong();
   private final AtomicLong uniqueChannelSubscriptions = new AtomicLong();
   private final AtomicLong uniquePatternSubscriptions = new AtomicLong();
-  private final ScheduledExecutorService perSecondExecutor;
+
+  private final int rollingAverageSamplesPerSecond = 16;

Review comment:
       I think this is a traditional constant so it would have to name it with 
all caps and underscores. As I was reading the code and saw it used I would 
have liked to know it was a constant that could never change.
   

##########
File path: 
geode-for-redis/src/main/java/org/apache/geode/redis/internal/statistics/RedisStats.java
##########
@@ -194,43 +201,49 @@ public void changeUniquePatternSubscriptions(long delta) {
 
   public void close() {
     geodeRedisStats.close();
-    stopPerSecondUpdater();
+    stopRollingAverageUpdater();
   }
 
-  private ScheduledExecutorService startPerSecondUpdater() {
-    int INTERVAL = 1;
+  private ScheduledExecutorService startRollingAverageUpdater() {
+    long microsPerSecond = 1_000_000;
+    final long delayMicros = microsPerSecond / rollingAverageSamplesPerSecond;
 
-    ScheduledExecutorService perSecondExecutor =
-        newSingleThreadScheduledExecutor("GemFireRedis-PerSecondUpdater-");
+    ScheduledExecutorService rollingAverageExecutor =
+        
newSingleThreadScheduledExecutor("GemFireRedis-RollingAverageStatUpdater-");
 
-    perSecondExecutor.scheduleWithFixedDelay(
-        this::doPerSecondUpdates,
-        INTERVAL,
-        INTERVAL,
-        SECONDS);
+    
rollingAverageExecutor.scheduleWithFixedDelay(this::doRollingAverageUpdates, 
delayMicros,
+        delayMicros, MICROSECONDS);
 
-    return perSecondExecutor;
+    return rollingAverageExecutor;
   }
 
-  private void stopPerSecondUpdater() {
-    perSecondExecutor.shutdownNow();
+  private void stopRollingAverageUpdater() {
+    rollingAverageExecutor.shutdownNow();
   }
 
-  private void doPerSecondUpdates() {
-    updateNetworkKilobytesReadLastSecond();
-    updateOpsPerformedOverLastSecond();
+  private void doRollingAverageUpdates() {
+    updateNetworkKilobytesReadLastSecond(rollingAverageTick);
+    updateOpsPerformedOverLastSecond(rollingAverageTick);
+    rollingAverageTick++;
+    if (rollingAverageTick >= rollingAverageSamplesPerSecond) {
+      rollingAverageTick = 0;
+    }
   }
 
-  private void updateNetworkKilobytesReadLastSecond() {
+  private void updateNetworkKilobytesReadLastSecond(int tickNumber) {
     final long totalNetworkBytesRead = getTotalNetworkBytesRead();
-    long deltaNetworkBytesRead = totalNetworkBytesRead - 
previousNetworkBytesRead;
-    networkKiloBytesReadOverLastSecond = deltaNetworkBytesRead / 1024.0;
-    previousNetworkBytesRead = totalNetworkBytesRead;
+    long deltaNetworkBytesRead = totalNetworkBytesRead - 
totalNetworkBytesReadLastTick;

Review comment:
       consider extracting this logic into a small class, RollingAverageStat 
that would have two fields: valueReadLastTick and valuesReadOverLastNSamples. 
It would have one method on it "long calculateRollingAverage(long)". You could 
call it like so: networkKiloBytesReadOverLastSecond = 
networkBytesRollingAverage.calculate(getTotalNetworkBytesRead()) / 1024.0 and 
also use it for opsPerformedOverLastSecond




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to