You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2013/04/13 16:19:38 UTC

svn commit: r1467641 - /uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java

Author: challngr
Date: Sat Apr 13 14:19:37 2013
New Revision: 1467641

URL: http://svn.apache.org/r1467641
Log:
UIMA-2799
Support for test AE to produce controlled memory bloat.
Specify PROCESS_BLOAT=xx where xx is in GB in the process environment.
The AE will bloat to that size by approximately halfway through its
execution, then hold steady.

To use in testing, specify -Xmx large enough to contain the bloat, and
the actual bloat size.  To test somehing like cgrouops, specify a
smaller memory, e.g.:
process_memory   = 4
process_jvm_args = -Xmx16G
process_environment = PROCESS_BLOAT=10

DUCC will assume the process is to be contained in 4GB, but the process
will bloat to about 10GB over half its lifetime.

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java?rev=1467641&r1=1467640&r2=1467641&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-examples/src/main/java/org/apache/uima/ducc/test/randomsleep/FixedSleepAE.java Sat Apr 13 14:19:37 2013
@@ -35,6 +35,8 @@ public class FixedSleepAE extends CasAnn
     Marker marker;
     String AE_Identifier = "*^^^^^^^^^ AE ";
 
+    ArrayList< long[] > bloated_space = new ArrayList< long[] >();
+
     @Override
     public void initialize(UimaContext uimaContext) throws ResourceInitializationException 
     {
@@ -167,7 +169,9 @@ public class FixedSleepAE extends CasAnn
         
     /**
      * Need to simulate a process that leaks.  We just allocate stuff until we die somehow.  
-     * Careful, this can be pretty nasty if not contained by the infrastructure.
+     * Careful, this can be pretty nasty if not contained by the infrastructure.  
+     *
+     * Older code = use the Bloater class for better results.
      */
     void runBloater(String gb)
     {
@@ -358,8 +362,9 @@ public class FixedSleepAE extends CasAnn
             dolog(msgheader + " sleeping " + elapsed + " MS.");
             String bloat = System.getenv("PROCESS_BLOAT");
             if ( bloat != null ) {
-                dolog(msgheader + " Running bloater instead of sleeping with bloat " + bloat);
-                runBloater(bloat);
+                long gb = Long.parseLong(bloat) * 1024 * 1024 * 1024;
+                Bloat bl = new Bloat(msgheader, gb, elapsed);
+                bl.start();
             }
 
             randomError(error_rate, msgheader);           
@@ -431,4 +436,54 @@ public class FixedSleepAE extends CasAnn
         }
     }
 
+    class Bloat
+        extends Thread
+    {
+        int NUM_UPDATES = 10;
+        long howmuch;
+        long elapsed;
+        String msgheader;
+        //
+        // want to bloat to max about halfway before the sleep exits, if possible
+        //
+        Bloat(String msgheader, long howmuch, long elapsed)
+        {
+            this.msgheader = msgheader;
+            this.howmuch = howmuch;            // total bloat, in bytes
+            this.elapsed = elapsed;            // how long this process will live
+        }
+        
+        void increase()
+        {
+            long amount = howmuch / NUM_UPDATES;
+            long current = 0;
+            long increment = 1024*1024*1024/8;                 // a gigish, in longs
+            while ( current < amount ) {                
+            	dolog(msgheader + " ====> Allocating " + (increment*8) + " bytes.");
+                long[]  longs = new long[ (int) increment ];  // approximately howmuch/NUM_UPDATES bytes
+                bloated_space.add(longs);
+                current += (increment*8);
+            	dolog(msgheader + " ====> Current " + current );
+            }
+            dolog(msgheader + " ====> Allocated " + current + " bytes.");
+        }
+        
+        public void run()
+        {
+            long bloat_target = elapsed/2;              // want to fully bloat after this long
+            long sleep_time = bloat_target/NUM_UPDATES; // will do in NUM_UPDATES increments, sleep this long
+            long total = 0;                             // how long i've slept
+            dolog(msgheader + " Starting bloater: " + howmuch + " bytes over " + bloat_target + " ms.");
+            while (total < bloat_target ) {             // done yet?
+                increase();                             // bloat a bit
+                try {
+                    dolog(msgheader + " Sleeping " + sleep_time + "ms");
+                    Thread.sleep(sleep_time);
+				} catch (InterruptedException e) {
+					// don't care
+				} 
+                total += sleep_time;                   // account for it
+            }
+        }
+    }
 }