Skip to content

Commit

Permalink
update to resource observer:
Browse files Browse the repository at this point in the history
- returns high/medium/low disk space
- pauses crawling on medium disk space
- disables index receive on low disk space

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5310 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
lotus committed Oct 31, 2008
1 parent 83967f8 commit 8d07607
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions source/de/anomic/crawler/ResourceObserver.java
Expand Up @@ -4,6 +4,8 @@
// (C) by Detlef Reichl; detlef!reichl()gmx!org
// Pforzheim, Germany, 2008
//
// changes by David Wieditz
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -39,14 +41,19 @@ public final class ResourceObserver {
private static final int CHECK_DISK_USAGE_FREQ = 1;
// The memory usage should be checked on every run
private static final int CHECK_MEMORY_USAGE_FREQ = 1;

// return values for available disk/memory
private static final int LOW = 0;
private static final int MEDIUM = 1;
private static final int HIGH = 2;

private final serverLog log = new serverLog("RESOURCE OBSERVER");
private final plasmaSwitchboard sb;

private int checkDiskUsageCount;
private int checkMemoryUsageCount;
private boolean disksOK;
private boolean memoryOK;
private int disksFree;
private int memoryFree;

public ResourceObserver(final plasmaSwitchboard sb) {
this.sb = sb;
Expand Down Expand Up @@ -76,35 +83,40 @@ public ResourceObserver(final plasmaSwitchboard sb) {

checkDiskUsageCount = 0;
checkMemoryUsageCount = 0;
disksOK = true;
memoryOK = true;
disksFree = HIGH;
memoryFree = HIGH;
}

public void resourceObserverJob() {
checkDiskUsageCount++;
checkMemoryUsageCount++;
boolean tmpDisksOK = true;
boolean tmpMemoryOK = true;
int tmpDisksFree = HIGH;
int tmpMemoryFree = HIGH;
if (checkDiskUsageCount >= CHECK_DISK_USAGE_FREQ) {
checkDiskUsageCount = 0;
tmpDisksOK = checkDisks();
disksOK = tmpDisksOK;
tmpDisksFree = checkDisks();
disksFree = tmpDisksFree;
}
if (checkMemoryUsageCount >= CHECK_MEMORY_USAGE_FREQ) {
checkMemoryUsageCount = 0;
tmpMemoryOK = checkMemory();
memoryOK = tmpMemoryOK;
tmpMemoryFree = checkMemory();
memoryFree = tmpMemoryFree;
}

if (!tmpDisksOK || !tmpMemoryOK) {
if (tmpDisksFree < HIGH || tmpMemoryFree < HIGH) {
if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL)) {
this.log.logInfo("disabling local crawls");
this.log.logInfo("pausing local crawls");
sb.pauseCrawlJob(plasmaSwitchboardConstants.CRAWLJOB_LOCAL_CRAWL);
}
if (!sb.crawlJobIsPaused(plasmaSwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL)) {
this.log.logInfo("disabling remote triggered crawls");
this.log.logInfo("pausing remote triggered crawls");
sb.pauseCrawlJob(plasmaSwitchboardConstants.CRAWLJOB_REMOTE_TRIGGERED_CRAWL);
}
if (tmpDisksFree == LOW && sb.getConfigBool(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false)) {
this.log.logInfo("disabling index receive");
sb.setConfig(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false);
sb.webIndex.seedDB.mySeed().setFlagAcceptRemoteIndex(false);
}
}
else {
if (diskUsage.isUsable())
Expand All @@ -115,11 +127,11 @@ public void resourceObserverJob() {
}

public boolean getDisksOK () {
return disksOK;
return disksFree == HIGH;
}

public boolean getMemoryOK () {
return memoryOK;
return memoryFree == HIGH;
}

/**
Expand All @@ -130,13 +142,19 @@ public long getMinFreeDiskSpace () {
}

/**
* @return enough disk space available?
* returns the amount of disk space available
* @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>
* </ul>
*/
private boolean checkDisks() {
boolean below = false;

private int checkDisks() {
int ret = HIGH;

if (!diskUsage.isUsable ())
return true;
return HIGH;

final HashMap<String, long[]> usage = diskUsage.getDiskUsage();
long[] val;
Expand All @@ -145,14 +163,17 @@ private boolean checkDisks() {
this.log.logInfo("df of Volume " + entry.getKey() + ": " + (val[1] / 1024 / 1024) + " MB");
if (val[1] < getMinFreeDiskSpace()) {
this.log.logWarning("Volume " + entry.getKey() + ": free space (" + (val[1] / 1024 / 1024) + " MB) is too low (< " + (getMinFreeDiskSpace() / 1024 / 1024) + " MB)");
below = true;
ret = MEDIUM;
}
if (val[1] < Math.min(getMinFreeDiskSpace() / 5L, 100L)) {
ret = LOW;
}
}
return !below;
return ret;
}

private boolean checkMemory() {
return true;
private int checkMemory() {
return HIGH;
}
}

0 comments on commit 8d07607

Please sign in to comment.