- if mem is too low but former GCs helped, the word-cache limit is only decreased now, if a subsequent GC doesn't

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3197 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
karlchenofhell 18 years ago
parent 4aec181643
commit 4dce5ec261

@ -232,6 +232,31 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
logError("thread '" + this.getName() + "': " + e.toString(),e);
}
}
private static long[] gcs = new long[5];
private static int gcs_pos = 0;
private static long runGC() {
long memnow = serverMemory.available();
Runtime.getRuntime().gc();
if (++gcs_pos >= gcs.length) gcs_pos = 0;
return (gcs[gcs_pos] = serverMemory.available() - memnow);
}
public static long GCAverage() {
long x = 0;
int y = 0;
for (int i=0; i<gcs.length; i++)
if (gcs[i] != 0) {
x += gcs[i];
y++;
}
if (y == 0) {
return 0;
} else {
return x / y;
}
}
public void run() {
if (startup > 0) {
@ -251,7 +276,7 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
long memstamp0, memstamp1, memnow;
boolean isBusy;
//Runtime rt = Runtime.getRuntime();
while (running) {
if ((this.intermissionObedient) && (this.intermission > 0) && (this.intermission != Long.MAX_VALUE)) {
long itime = this.intermission - System.currentTimeMillis();
@ -271,7 +296,8 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
timestamp = System.currentTimeMillis();
ratz(this.idlePause);
idletime += System.currentTimeMillis() - timestamp;
} else if ((memnow = serverMemory.available()) > memprereq) try {
} else if ((memnow = serverMemory.available()) > memprereq ||
((memnow + GCAverage() > memprereq || GCAverage() == 0) && memnow + runGC() > memprereq)) try {
// do job
timestamp = System.currentTimeMillis();
memstamp0 = serverMemory.used();
@ -304,8 +330,9 @@ public abstract class serverAbstractThread extends Thread implements serverThrea
this.jobExceptionHandler(e);
busyCycles++;
} else {
log.logFine("Thread '" + this.getName() + "' runs short memory cycle. Free mem: " +
(memnow / 1024) + " KB, needed: " + (memprereq / 1024) + " KB");
log.logWarning("Thread '" + this.getName() + "' runs short memory cycle. Free mem: " +
(memnow / 1024) + " KB, needed: " + (memprereq / 1024) + " KB, " +
"GC should provide max. " + (GCAverage() / 1024) + "KB");
// omit job, not enough memory
// process scheduled pause
timestamp = System.currentTimeMillis();

Loading…
Cancel
Save