You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2008/03/20 20:02:01 UTC

svn commit: r639409 - in /incubator/pig/trunk: CHANGES.txt src/org/apache/pig/impl/util/SpillableMemoryManager.java

Author: gates
Date: Thu Mar 20 12:02:00 2008
New Revision: 639409

URL: http://svn.apache.org/viewvc?rev=639409&view=rev
Log:
 PIG-164:  Fix memory issue in SpillableMemoryManager to partially clean the list of bags each time a new bag is added rather than waiting until the garbage collector tells us we are out of memory.

Modified:
    incubator/pig/trunk/CHANGES.txt
    incubator/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java

Modified: incubator/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=639409&r1=639408&r2=639409&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Thu Mar 20 12:02:00 2008
@@ -169,3 +169,7 @@
 
 	PIG-106:  Change StringBuffer and String '+' to StringBuilder (francisoud
 	via gates).
+
+	PIG-164:  Fix memory issue in SpillableMemoryManager to partially clean the list of
+	bags each time a new bag is added rather than waiting until the garbage
+	collector tells us we are out of memory (gates).

Modified: incubator/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java
URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java?rev=639409&r1=639408&r2=639409&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/util/SpillableMemoryManager.java Thu Mar 20 12:02:00 2008
@@ -32,7 +32,7 @@
     
     private final Log log = LogFactory.getLog(getClass());
     
-    List<WeakReference<Spillable>> spillables = new LinkedList<WeakReference<Spillable>>();
+    LinkedList<WeakReference<Spillable>> spillables = new LinkedList<WeakReference<Spillable>>();
     
     public SpillableMemoryManager() {
         ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
@@ -142,6 +142,13 @@
      */
     public void registerSpillable(Spillable s) {
         synchronized(spillables) {
+            // Cleaing the entire list is too expensive.  Just trim off the front while
+            // we can.
+            WeakReference<Spillable> first = spillables.peek();
+            while (first != null && first.get() == null) {
+                spillables.remove();
+                first = spillables.peek();
+            }
             spillables.add(new WeakReference<Spillable>(s));
         }
     }