(peak-) performance hacks

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5819 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 63cd152969
commit e16c25ddf7

@ -71,13 +71,12 @@ public class PerformanceMemory_p {
final long memoryTotalAfterInitBGC = Long.parseLong(env.getConfig("memoryTotalAfterInitBGC", "0"));
final long memoryTotalAfterInitAGC = Long.parseLong(env.getConfig("memoryTotalAfterInitAGC", "0"));
final long memoryTotalAfterStartup = Long.parseLong(env.getConfig("memoryTotalAfterStartup", "0"));
final long memoryMax = MemoryControl.max();
prop.putNum("memoryMax", memoryMax / MB);
prop.putNum("memoryAvailAfterStartup", (memoryMax - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB);
prop.putNum("memoryAvailAfterInitBGC", (memoryMax - memoryTotalAfterInitBGC + memoryFreeAfterInitBGC) / MB);
prop.putNum("memoryAvailAfterInitAGC", (memoryMax - memoryTotalAfterInitAGC + memoryFreeAfterInitAGC) / MB);
prop.putNum("memoryAvailNow", (memoryMax - memoryTotalNow + memoryFreeNow) / MB);
prop.putNum("memoryMax", MemoryControl.maxMemory / MB);
prop.putNum("memoryAvailAfterStartup", (MemoryControl.maxMemory - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB);
prop.putNum("memoryAvailAfterInitBGC", (MemoryControl.maxMemory - memoryTotalAfterInitBGC + memoryFreeAfterInitBGC) / MB);
prop.putNum("memoryAvailAfterInitAGC", (MemoryControl.maxMemory - memoryTotalAfterInitAGC + memoryFreeAfterInitAGC) / MB);
prop.putNum("memoryAvailNow", (MemoryControl.maxMemory - memoryTotalNow + memoryFreeNow) / MB);
prop.putNum("memoryTotalAfterStartup", memoryTotalAfterStartup / KB);
prop.putNum("memoryTotalAfterInitBGC", memoryTotalAfterInitBGC / KB);
prop.putNum("memoryTotalAfterInitAGC", memoryTotalAfterInitAGC / KB);

@ -273,7 +273,7 @@ public class Status {
// memory usage and system attributes
prop.put("freeMemory", Formatter.bytesToString(MemoryControl.free()));
prop.put("totalMemory", Formatter.bytesToString(MemoryControl.total()));
prop.put("maxMemory", Formatter.bytesToString(MemoryControl.max()));
prop.put("maxMemory", Formatter.bytesToString(MemoryControl.maxMemory));
prop.put("processors", serverProcessor.availableCPU);
// proxy traffic

@ -30,7 +30,7 @@ public class status_p {
// memory usage and system attributes
prop.putNum("freeMemory", MemoryControl.free());
prop.putNum("totalMemory", MemoryControl.total());
prop.putNum("maxMemory", MemoryControl.max());
prop.putNum("maxMemory", MemoryControl.maxMemory);
prop.putNum("processors", serverProcessor.availableCPU);
// proxy traffic

@ -377,12 +377,12 @@ public class dbtest {
System.out.println("Loop " + loop + ": Write = " + write + ", Remove = " + remove);
System.out.println(" bevore GC: " +
"free = " + MemoryControl.free() +
", max = " + MemoryControl.max() +
", max = " + MemoryControl.maxMemory +
", total = " + MemoryControl.total());
System.gc();
System.out.println(" after GC: " +
"free = " + MemoryControl.free() +
", max = " + MemoryControl.max() +
", max = " + MemoryControl.maxMemory +
", total = " + MemoryControl.total());
loop++;
}

@ -32,8 +32,11 @@ import de.anomic.tools.Formatter;
*/
public class MemoryControl {
private static final Runtime runtime = Runtime.getRuntime();
private static final Log log = new Log("MEMORY");
public static long maxMemory = runtime.maxMemory(); // this value does never change during runtime
private static final Log log = new Log("MEMORY");
private static final long[] gcs = new long[5];
private static int gcs_pos = 0;
@ -99,17 +102,8 @@ public class MemoryControl {
* @return bytes
*/
public static final long available() {
return max() - total() + free();
return maxMemory - total() + free();
}
/**
* maximum memory which the vm can use
* @return bytes
*/
public static final long max()
{
return runtime.maxMemory();
}
/**
* currently allocated memory in the Java virtual machine; may vary over time
@ -140,13 +134,14 @@ public class MemoryControl {
* @return whether enough memory could be freed (or is free) or not
*/
public static boolean request(final long size, final boolean force) {
final long avg = getAverageGCFree();
if (avg >= size) return true;
long avail = available();
if (avail >= size) return true;
if (log.isFine()) {
final String t = new Throwable("Stack trace").getStackTrace()[1].toString();
log.logFine(t + " requested " + (size >> 10) + " KB, got " + (avail >> 10) + " KB");
}
final long avg = getAverageGCFree();
if (force || avg == 0 || avg + avail >= size) {
// this is only called if we expect that an allocation of <size> bytes would cause the jvm to call the GC anyway
@ -183,7 +178,7 @@ public class MemoryControl {
// try this with a jvm 1.4.2 and with a jvm 1.5 and compare results
final int mb = 1024 * 1024;
System.out.println("vm: " + System.getProperty("java.vm.version"));
System.out.println("computed max = " + (max() / mb) + " mb");
System.out.println("computed max = " + (maxMemory / mb) + " mb");
final int alloc = 10000;
final byte[][] x = new byte[100000][];
for (int i = 0; i < 100000; i++) {
@ -191,7 +186,7 @@ public class MemoryControl {
if (i % 100 == 0) System.out.println("used = " + (i * alloc / mb) +
", total = " + (total() / mb) +
", free = " + (free() / mb) +
", max = " + (max() / mb) +
", max = " + (maxMemory / mb) +
", avail = " + (available() / mb));
}

@ -672,7 +672,7 @@ public final class yacy {
// db used to hold all neede urls
final MetadataRepository minimizedUrlDB = new MetadataRepository(new File(new File(indexRoot2, networkName), "TEXT"));
final int cacheMem = (int)(MemoryControl.max() - MemoryControl.total());
final int cacheMem = (int)(MemoryControl.maxMemory - MemoryControl.total());
if (cacheMem < 2048000) throw new OutOfMemoryError("Not enough memory available to start clean up.");
final plasmaWordIndex wordIndex = new plasmaWordIndex(networkName, log, indexPrimaryRoot, indexSecondaryRoot, 10000, false, 1, 0, false);

Loading…
Cancel
Save