geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [1/2] incubator-geode git commit: added mightSendEvent method to optimize off-heap resource manager event delivery
Date Wed, 12 Aug 2015 22:32:43 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-212 [created] 2b4e7f64d


added mightSendEvent method to optimize off-heap resource manager event delivery


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3b3acc7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3b3acc7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3b3acc7f

Branch: refs/heads/feature/GEODE-212
Commit: 3b3acc7fe38141ea2681cc2d9b415c8984779a69
Parents: 9de95d6
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Wed Aug 12 13:49:48 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Wed Aug 12 13:49:48 2015 -0700

----------------------------------------------------------------------
 .../internal/cache/control/MemoryEvent.java     |  2 +-
 .../cache/control/OffHeapMemoryMonitor.java     | 34 ++++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3b3acc7f/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/MemoryEvent.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/MemoryEvent.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/MemoryEvent.java
index bda6518..2e4468f 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/MemoryEvent.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/MemoryEvent.java
@@ -19,7 +19,7 @@ import com.gemstone.gemfire.internal.cache.control.MemoryThresholds.MemoryState;
  */
 public class MemoryEvent implements ResourceEvent {
   private final ResourceType type;
-  private volatile MemoryState state;
+  private final MemoryState state;
   private final MemoryState previousState;
   private final DistributedMember member;
   private final long bytesUsed;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3b3acc7f/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
index a1856e4..bd29f88 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/control/OffHeapMemoryMonitor.java
@@ -119,6 +119,9 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
 
   @Override
   public void updateMemoryUsed(final long bytesUsed) {
+    if (!mightSendEvent(bytesUsed)) {
+      return;
+    }
     synchronized (this.offHeapMemoryUsageListener) {
       this.offHeapMemoryUsageListener.offHeapMemoryUsed = bytesUsed;
       this.offHeapMemoryUsageListener.notifyAll();
@@ -232,7 +235,7 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
    * Public for testing.
    * 
    * @param bytesUsed
-   *          Number of bytes of heap memory currently used.
+   *          Number of bytes of off-heap memory currently used.
    */
   public void updateStateAndSendEvent(long bytesUsed) {
     synchronized (this) {
@@ -251,7 +254,9 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
       // The state didn't change.  However, if the state isn't normal and we've
       // been in that state for a while, send another event with the updated
       // memory usage.
-      } else if (!oldState.isNormal() && (System.currentTimeMillis() - this.mostRecentEvent.getEventTime())
> 1000) {
+      } else if (!oldState.isNormal()
+          && bytesUsed != this.mostRecentEvent.getBytesUsed()
+          && (System.currentTimeMillis() - this.mostRecentEvent.getEventTime()) >
1000) {
         MemoryEvent event = new MemoryEvent(ResourceType.OFFHEAP_MEMORY, oldState, newState,
this.cache.getMyId(), bytesUsed, true,
             this.thresholds);
         this.upcomingEvent.set(event);
@@ -259,6 +264,31 @@ public class OffHeapMemoryMonitor implements ResourceMonitor, MemoryUsageListene
       }
     }
   }
+  
+  /**
+   * Return true if the given number of bytes compared to the
+   * current monitor state would generate a new memory event.
+   * 
+   * @param bytesUsed
+   *          Number of bytes of off-heap memory currently used.
+   * @return true if a new event might need to be sent
+   */
+   private boolean mightSendEvent(long bytesUsed) {
+     MemoryEvent mre = this.mostRecentEvent;
+     MemoryState oldState = mre.getState();
+     MemoryState newState = this.thresholds.computeNextState(oldState, bytesUsed);
+     if (oldState != newState) {
+       return true;
+     // The state didn't change.  However, if the state isn't normal and we've
+     // been in that state for a while, send another event with the updated
+     // memory usage.
+     } else if (!oldState.isNormal()
+         && bytesUsed != mre.getBytesUsed()
+         && (System.currentTimeMillis() - mre.getEventTime()) > 1000) {
+       return true;
+     }
+     return false;
+  }
 
   /**
    * Update resource manager stats based upon the given event.


Mime
View raw message