From bf0ad04e1be08dd5408e970c689d7acf89f63a25 Mon Sep 17 00:00:00 2001 From: orbiter Date: Sat, 27 Jul 2013 10:42:38 +0200 Subject: [PATCH] apply load limitation also to dht-in --- defaults/yacy.init | 2 +- htroot/yacy/transferRWI.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/defaults/yacy.init b/defaults/yacy.init index c5e81bea2..defec0ef5 100644 --- a/defaults/yacy.init +++ b/defaults/yacy.init @@ -837,7 +837,7 @@ indexControl.gzipBody = true indexControl.timeout = 60000 indexDistribution.timeout = 60000 indexTransfer.timeout = 120000 -indexTransfer.maxload = 2.5 +indexTransfer.maxload = 2.2 # defining max. allowed amount of open files during index- transfer/distribution indexDistribution.maxOpenFiles = 800 diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java index 5d05627fd..436ed9ddc 100644 --- a/htroot/yacy/transferRWI.java +++ b/htroot/yacy/transferRWI.java @@ -40,6 +40,7 @@ import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.storage.HandleSet; import net.yacy.cora.util.ConcurrentLog; +import net.yacy.cora.util.Memory; import net.yacy.cora.util.SpaceExceededException; import net.yacy.kelondro.data.meta.URIMetadataRow; import net.yacy.kelondro.data.word.WordReferenceRow; @@ -105,7 +106,14 @@ public final class transferRWI { String result = "ok"; final StringBuilder unknownURLs = new StringBuilder(6000); - if ((youare == null) || (!youare.equals(sb.peers.mySeed().hash))) { + double load = Memory.load(); + float maxload = sb.getConfigFloat(SwitchboardConstants.INDEX_TRANSFER_MAXLOAD, 1.5f); + if (load > maxload) { + // too high local load. this is bad but we must reject this to protect ourself! + sb.getLog().info("Rejecting RWIs from peer " + otherPeerName + ", system has too high load = " + load + ", maxload = " + maxload); + result = "not_granted"; + pause = (int) (load * 20000); + } else if ((youare == null) || (!youare.equals(sb.peers.mySeed().hash))) { sb.getLog().info("Rejecting RWIs from peer " + otherPeerName + ". Wrong target. Wanted peer=" + youare + ", iam=" + sb.peers.mySeed().hash); result = "wrong_target"; pause = 0;