From 713cb26a2764bafa66d29904ff03b203694c2757 Mon Sep 17 00:00:00 2001 From: lotus Date: Sun, 6 Dec 2009 17:45:48 +0000 Subject: [PATCH] update for memory observer algorithm disable dht if memory is less than treshold after 4 times, maximum 11 minutes between each detection git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6517 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- getWin32MaxHeap.bat | 2 +- .../net/yacy/kelondro/util/MemoryControl.java | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/getWin32MaxHeap.bat b/getWin32MaxHeap.bat index f4c120565..a15700521 100644 --- a/getWin32MaxHeap.bat +++ b/getWin32MaxHeap.bat @@ -3,5 +3,5 @@ echo This can cause high system load. echo To abort press CTRL+C. echo *** pause -java -cp lib net.yacy.kelondro.util.OS -m +java -cp lib\yacycore.jar net.yacy.kelondro.util.OS -m pause \ No newline at end of file diff --git a/source/net/yacy/kelondro/util/MemoryControl.java b/source/net/yacy/kelondro/util/MemoryControl.java index 3618c159f..16a2a8037 100644 --- a/source/net/yacy/kelondro/util/MemoryControl.java +++ b/source/net/yacy/kelondro/util/MemoryControl.java @@ -43,7 +43,9 @@ public class MemoryControl { private static long lastGC = 0l; - private static long DHTkbytes = 0; + private static long DHTkbytes = 0L; + private static long prevDHTtreshold = 0L; + private static int DHTtresholdCount = 0; private static boolean allowDHT = true; /** @@ -178,12 +180,27 @@ public class MemoryControl { return allowDHT; } - public static void setDHTkbytes(long kbytes) { + public static void setDHTallowed() { + allowDHT = true; + } + + public static void setDHTkbytes(final long kbytes) { DHTkbytes = kbytes; } - private static void checkDHTrule(long available) { - if ((available >> 10) < DHTkbytes) allowDHT = false; + private static void checkDHTrule(final long available) { + // disable dht if memory is less than treshold - 4 times, maximum 11 minutes between each detection + if ((available >> 10) < DHTkbytes) { + final long t = System.currentTimeMillis(); + if(prevDHTtreshold + 11L /* minutes */ * 60000L > t) { + DHTtresholdCount++; + if(DHTtresholdCount > 3 /* occurencies - 1 */) allowDHT = false; + } + else DHTtresholdCount = 1; + + prevDHTtreshold = t; + } + //allowDHT = ((available >> 10) < DHTkbytes) ? false : true; // stupid } /**