Changeset 393

Show
Ignore:
Timestamp:
08/04/10 18:11:40 (2 years ago)
Author:
ke
Message:

ObjectMagazine? was calculating present memory usage in a way that didn't make sense: freeMemory / min(totalMemory + maxMemory). It should be (totalMemory - freeMemory) in the numerator. Also, changed the denominator to just totalMemory, giving up the probably misguided ambition to stay far below the maximum allowed memory size.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • kahina/trunk/src/org/kahina/core/io/magazine/ObjectMagazine.java

    r390 r393  
    2323import org.kahina.core.util.ProgressMonitorWrapper; 
    2424 
     25/** 
     26 * Stores objects in memory by default, but serializes them away to disk in 
     27 * blocks when memory usage exceeds a specified threshold. The idea is from 
     28 * {@url http://forums.sun.com/thread.jspa?messageID=10949277#10949277}. 
     29 * @author ke 
     30 * 
     31 * @param <S> 
     32 */ 
    2533public class ObjectMagazine<S> 
    2634{ 
    27         private static final boolean VERBOSE = false; 
     35        private static final boolean VERBOSE = true; 
    2836 
    2937        private final File folder; 
     
    124132                                ns = System.nanoTime(); 
    125133                        } 
     134                        // TODO Comparing memory usage to the lower bound doesn't really 
     135                        // make sense, the VM will keep all the garbage lying around. Maybe 
     136                        // just reduce to a fixed number of blocks (like 10) and explicitly 
     137                        // garbage-collect then. 
    126138                        while (blockNumbersUnloadQueue.size() > 1 && memoryRatio() > lowerBound) 
    127139                        { 
     
    138150        private float memoryRatio() 
    139151        { 
    140                 return ((float) runtime.totalMemory()) / Math.min(runtime.maxMemory(), runtime.freeMemory()); 
     152                if (VERBOSE) 
     153                { 
     154                        System.err.println("Total memory: " + runtime.totalMemory()); 
     155                        System.err.println("Max memory:   " + runtime.maxMemory()); 
     156                        System.err.println("Free memory:  " + runtime.freeMemory()); 
     157                        System.err.println("Ratio: " + ((float) (runtime.totalMemory() - runtime.freeMemory())) / runtime.maxMemory()); 
     158                } 
     159                return ((float) (runtime.totalMemory() - runtime.freeMemory())) / runtime.maxMemory(); 
    141160        } 
    142161