small memory leak patch

pull/1/head
Michael Peter Christen 12 years ago
parent b24d1d18e4
commit 77faeada4d

@ -43,6 +43,7 @@ public class Latency {
private final static int DEFAULT_AVERAGE = 300; private final static int DEFAULT_AVERAGE = 300;
// the map is a mapping from host names to host configurations // the map is a mapping from host names to host configurations
private static final int mapMaxSize = 1000;
private static final ConcurrentHashMap<String, Host> map = new ConcurrentHashMap<String, Host>(); private static final ConcurrentHashMap<String, Host> map = new ConcurrentHashMap<String, Host>();
/** /**
@ -57,7 +58,7 @@ public class Latency {
Host h = map.get(hosthash); Host h = map.get(hosthash);
if (h == null) { if (h == null) {
h = new Host(host, DEFAULT_AVERAGE, robotsCrawlDelay); h = new Host(host, DEFAULT_AVERAGE, robotsCrawlDelay);
if (map.size() > 1000 || MemoryControl.shortStatus()) map.clear(); if (map.size() > mapMaxSize || MemoryControl.shortStatus()) map.clear();
map.put(hosthash, h); map.put(hosthash, h);
} }
} }
@ -74,7 +75,7 @@ public class Latency {
Host h = map.get(hosthash); Host h = map.get(hosthash);
if (h == null) { if (h == null) {
h = new Host(host, 500, 0); h = new Host(host, 500, 0);
if (map.size() > 1000 || MemoryControl.shortStatus()) map.clear(); if (map.size() > mapMaxSize || MemoryControl.shortStatus()) map.clear();
map.put(hosthash, h); map.put(hosthash, h);
} else { } else {
h.update(); h.update();
@ -93,7 +94,7 @@ public class Latency {
Host h = map.get(hosthash); Host h = map.get(hosthash);
if (h == null) { if (h == null) {
h = new Host(host, time, 0); h = new Host(host, time, 0);
if (map.size() > 1000 || MemoryControl.shortStatus()) map.clear(); if (map.size() > mapMaxSize || MemoryControl.shortStatus()) map.clear();
map.put(hosthash, h); map.put(hosthash, h);
} else { } else {
h.update(time); h.update(time);

@ -65,6 +65,7 @@ import net.yacy.search.Switchboard;
public final class LoaderDispatcher { public final class LoaderDispatcher {
private final static int accessTimeMaxsize = 1000;
private static final ConcurrentHashMap<String, Long> accessTime = new ConcurrentHashMap<String, Long>(); // to protect targets from DDoS private static final ConcurrentHashMap<String, Long> accessTime = new ConcurrentHashMap<String, Long>(); // to protect targets from DDoS
private final Switchboard sb; private final Switchboard sb;
@ -271,7 +272,10 @@ public final class LoaderDispatcher {
} }
// now it's for sure that we will access the target. Remember the access time // now it's for sure that we will access the target. Remember the access time
if (host != null) accessTime.put(host, System.currentTimeMillis()); if (host != null) {
if (accessTime.size() > accessTimeMaxsize) accessTime.clear(); // prevent a memory leak here
accessTime.put(host, System.currentTimeMillis());
}
// load resource from the internet // load resource from the internet
Response response = null; Response response = null;

Loading…
Cancel
Save