From ba44eb11602dbd0625de46b11c56089aec217577 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Thu, 16 Jan 2014 17:34:26 +0100 Subject: [PATCH] when scaling the number of remote peers, also consider the machine load and the number of cores --- source/net/yacy/cora/util/Memory.java | 8 ++++++++ source/net/yacy/peers/RemoteSearch.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/source/net/yacy/cora/util/Memory.java b/source/net/yacy/cora/util/Memory.java index 33b483206..569e72c55 100644 --- a/source/net/yacy/cora/util/Memory.java +++ b/source/net/yacy/cora/util/Memory.java @@ -66,6 +66,14 @@ public class Memory { public static final long used() { return total() - free(); } + + /** + * get number of CPU cores + * @return number of CPU cores + */ + public static final long cores() { + return runtime.availableProcessors(); + } /** * get the system load within the last minute diff --git a/source/net/yacy/peers/RemoteSearch.java b/source/net/yacy/peers/RemoteSearch.java index 08e24cea0..f316a768f 100644 --- a/source/net/yacy/peers/RemoteSearch.java +++ b/source/net/yacy/peers/RemoteSearch.java @@ -34,6 +34,7 @@ import org.apache.solr.client.solrj.SolrQuery; import net.yacy.cora.document.encoding.ASCII; import net.yacy.cora.storage.HandleSet; import net.yacy.cora.util.ConcurrentLog; +import net.yacy.cora.util.Memory; import net.yacy.kelondro.util.MemoryControl; import net.yacy.repository.Blacklist; import net.yacy.search.Switchboard; @@ -145,6 +146,9 @@ public class RemoteSearch extends Thread { int redundancy = event.peers.redundancy(); if (indexingQueueSize > 10) redundancy = Math.max(1, redundancy - 1); if (indexingQueueSize > 50) redundancy = Math.max(1, redundancy - 1); + if (Memory.load() > 2.0) redundancy = Math.max(1, redundancy - 1); + if (Memory.cores() < 4) redundancy = Math.max(1, redundancy - 1); + if (Memory.cores() == 1) redundancy = 1; int minage = 3; int robinsoncount = event.peers.scheme.verticalPartitions() * redundancy / 2; if (indexingQueueSize > 10) robinsoncount = Math.max(1, robinsoncount / 2);