gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz gzz/mem/MemoryPartitioner.java test/gzz/mem...


From: Tuomas J. Lukka
Subject: [Gzz-commits] gzz gzz/mem/MemoryPartitioner.java test/gzz/mem...
Date: Wed, 08 Jan 2003 09:04:15 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tuomas J. Lukka <address@hidden>        03/01/08 09:04:14

Modified files:
        gzz/mem        : MemoryPartitioner.java 
        test/gzz/mem   : partition.test 

Log message:
        Somewhat better

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/mem/MemoryPartitioner.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/test/gzz/mem/partition.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/gzz/mem/MemoryPartitioner.java
diff -u gzz/gzz/mem/MemoryPartitioner.java:1.3 
gzz/gzz/mem/MemoryPartitioner.java:1.4
--- gzz/gzz/mem/MemoryPartitioner.java:1.3      Wed Jan  8 08:51:20 2003
+++ gzz/gzz/mem/MemoryPartitioner.java  Wed Jan  8 09:04:14 2003
@@ -11,6 +11,9 @@
  * MemoryConsumers.
  */
 public class MemoryPartitioner {
+    public static boolean dbg = true;
+    static final void pa(String s) { System.out.println(s); }
+
     /** The amount of memory reserved to MemoryConsumers.
      * Let's start with 64MB
      */
@@ -78,6 +81,7 @@
                else
                    curQuality -= .02 * (curQuality - q);
            }
+           if(dbg) pa("Bgupdate: "+i+" "+q+" "+curImportance+" "+curQuality);
        }
 
        void update(float importance, float quality, Obs o) {
@@ -134,11 +138,15 @@
 
     }
 
+    boolean keepRepartitioner = true;
     Thread repartitioner = new Thread() {
        public void run() {
            while(true) {
+               if(!keepRepartitioner) return;
                try {
+                   if(dbg) pa("Going to rerate\n");
                    rerate();
+                   if(dbg) pa("rerated, sleeping\n");
                    Thread.sleep(10);
                } catch(Exception e) { 
                    ZZLogger.exc(e, "gzz.mem.MemoryPartitioner thread!");
@@ -150,11 +158,12 @@
     /** Reallocate all memory.
      */
     private void rerate() {
-       // Sum of maxbytes with priority 1
-       int sum1 = 0;
-       // Sum of maxbytes multiplied with priority^round
-       int sumReduced = 0;
        for(int round = 0; ; round++) {
+           // Sum of maxbytes with priority 1
+           int sum1 = 0;
+           // Sum of maxbytes multiplied with priority^round
+           int sumReduced = 0;
+           if(dbg) pa("Rerate round "+round);
            for(Iterator i = consumer2record.keySet().iterator(); i.hasNext(); 
) {
                MemoryConsumer cons = (MemoryConsumer)i.next();
                ConsumerRecord rec = (ConsumerRecord)consumer2record.get(cons);
@@ -169,6 +178,7 @@
                    sum1 += byt;
                sumReduced += (int)(imp * byt);
            }
+           if(dbg) pa("Counted: "+sum1+" "+sumReduced);
            if(sum1 > memory) {
                // Problem! Not enough memory for all 1-importances
                // - fill from start as many as we can
@@ -197,6 +207,7 @@
                    int byt = cons.getMaxBytes(rec.curQuality);
                    rec.fit(cons, (int)(imp * byt));
                }
+               return;
            }
            // didn't fit - try with a larger exponent
        }
@@ -208,7 +219,7 @@
     }
 
     public void stop() {
-       repartitioner.stop();
+       keepRepartitioner = false;
     }
 }
 
Index: gzz/test/gzz/mem/partition.test
diff -u gzz/test/gzz/mem/partition.test:1.1 gzz/test/gzz/mem/partition.test:1.2
--- gzz/test/gzz/mem/partition.test:1.1 Wed Jan  8 08:51:20 2003
+++ gzz/test/gzz/mem/partition.test     Wed Jan  8 09:04:14 2003
@@ -4,7 +4,6 @@
 import java
 
 # room for 2, not 3
-pool = gzz.mem.MemoryPartitioner(500)
 
 class Reserver(gzz.mem.MemoryConsumer):
     def __init__(self):
@@ -25,6 +24,7 @@
 
     fail: *
     """
+    pool = gzz.mem.MemoryPartitioner(500)
     b = Reserver()
 
     pool.request(b, 1, 1, None)
@@ -33,6 +33,8 @@
        java.lang.Thread.sleep(50)
        print "Reserved: ",b.rese
        if b.rese == 230:
+           pool.stop()
            return
+    pool.stop()
     failUnless(0)
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]