Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
option to disable dht by memory limit: memory.acceptDHT in kbytes not yet pre-enabled, will clear on every startup please review since this could break dht in freeworld
lotus6edc168cfed1
diff --git a/defaults/yacy.init b/defaults/yacy.initindex 2ee5561fa..d77b814f2 100644--- a/defaults/yacy.init+++ b/defaults/yacy.init@@ -899,6 +899,9 @@ disk.free = 3000# minimum for DHT or 1/5th of former, whatever is maxdisk.free.hardlimit = 1000+# minimum memory to accept dht-in (KB)+#memory.acceptDHT = 10000+# setting if execution of CGI files is allowed or notcgi.allow = falsecgi.suffixes = cgi,pldiff --git a/source/de/anomic/crawler/ResourceObserver.java b/source/de/anomic/crawler/ResourceObserver.javaindex 2a88a2ad0..af9ba5989 100644--- a/source/de/anomic/crawler/ResourceObserver.java+++ b/source/de/anomic/crawler/ResourceObserver.java@@ -30,6 +30,7 @@ import java.util.Map;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.util.DiskSpace;+import net.yacy.kelondro.util.MemoryControl;import de.anomic.search.Switchboard;import de.anomic.search.SwitchboardConstants;@@ -105,6 +106,8 @@ public final class ResourceObserver {* checks the resources and pauses crawls if necessary*/public void resourceObserverJob() {+ MemoryControl.setDHTkbytes(sb.getConfigLong(SwitchboardConstants.MEMORY_ACCEPTDHT, 0));+checkDiskUsageCount++;checkMemoryUsageCount++;int tmpDisksFree = HIGH;@@ -121,15 +124,15 @@ public final class ResourceObserver {}if (tmpDisksFree < HIGH || tmpMemoryFree < HIGH) {- if (!sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {+ if (tmpDisksFree < HIGH && !sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {log.logInfo("pausing local crawls");sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);}- if (!sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {+ if (tmpDisksFree < HIGH && !sb.crawlJobIsPaused(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {log.logInfo("pausing remote triggered crawls");sb.pauseCrawlJob(SwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);}- if (tmpDisksFree == LOW && sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false)) {+ if ((tmpDisksFree == LOW || tmpMemoryFree < HIGH) && sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false)) {log.logInfo("disabling index receive");sb.setConfig(SwitchboardConstants.INDEX_RECEIVE_ALLOW, false);sb.peers.mySeed().setFlagAcceptRemoteIndex(false);@@ -176,7 +179,7 @@ public final class ResourceObserver {* @return <ul>* <li><code>HIGH</code> if disk space is available</li>* <li><code>MEDIUM</code> if low disk space is available</li>- * <li><code>LOW</code> if lower than 100MB or 1/5 disk space is available</li>+ * <li><code>LOW</code> if lower than hardlimit or 1/5 disk space is available (the max)</li>* </ul>*/private int checkDisks() {@@ -202,6 +205,7 @@ public final class ResourceObserver {}private int checkMemory() {+ if(!MemoryControl.getDHTallowed()) return LOW;return HIGH;}}diff --git a/source/de/anomic/search/SwitchboardConstants.java b/source/de/anomic/search/SwitchboardConstants.javaindex 44473c938..a994f4655 100644--- a/source/de/anomic/search/SwitchboardConstants.java+++ b/source/de/anomic/search/SwitchboardConstants.java@@ -392,6 +392,7 @@ public final class SwitchboardConstants {public static final String DISK_FREE = "disk.free";public static final String DISK_FREE_HARDLIMIT = "disk.free.hardlimit";+ public static final String MEMORY_ACCEPTDHT = "memory.acceptDHT";/** Some constantsdiff --git a/source/net/yacy/kelondro/util/MemoryControl.java b/source/net/yacy/kelondro/util/MemoryControl.javaindex 577a21df8..3618c159f 100644--- a/source/net/yacy/kelondro/util/MemoryControl.java+++ b/source/net/yacy/kelondro/util/MemoryControl.java@@ -42,6 +42,9 @@ public class MemoryControl {private static int gcs_pos = 0;private static long lastGC = 0l;++ private static long DHTkbytes = 0;+ private static boolean allowDHT = true;/*** Runs the garbage collector if last garbage collection is more than last millis ago@@ -154,6 +157,7 @@ public class MemoryControl {+ " KB (requested/available/average: "+ (size >> 10) + " / " + (avail >> 10) + " / " + (avg >> 10) + " KB)");}+ checkDHTrule(avail);return avail >= size;} else {if (log.isFine()) log.logFine("former GCs indicate to not be able to free enough memory (requested/available/average: "@@ -169,6 +173,18 @@ public class MemoryControl {public static long used() {return total() - free();}++ public static boolean getDHTallowed() {+ return allowDHT;+ }++ public static void setDHTkbytes(long kbytes) {+ DHTkbytes = kbytes;+ }++ private static void checkDHTrule(long available) {+ if ((available >> 10) < DHTkbytes) allowDHT = false;+ }/*** main