diff --git a/source/de/anomic/kelondro/text/IndexCell.java b/source/de/anomic/kelondro/text/IndexCell.java index e563d7037..187d5b891 100644 --- a/source/de/anomic/kelondro/text/IndexCell.java +++ b/source/de/anomic/kelondro/text/IndexCell.java @@ -98,14 +98,18 @@ public final class IndexCell extends AbstractBu */ public void add(ReferenceContainer newEntries) throws IOException { this.ram.add(newEntries); - serverProfiling.update("wordcache", Long.valueOf(this.ram.size()), true); - cleanCache(); + if (this.ram.size() % 100 == 0) { + serverProfiling.update("wordcache", Long.valueOf(this.ram.size()), true); + cleanCache(); + } } public void add(byte[] termHash, ReferenceType entry) throws IOException { this.ram.add(termHash, entry); - serverProfiling.update("wordcache", Long.valueOf(this.ram.size()), true); - cleanCache(); + if (this.ram.size() % 100 == 0) { + serverProfiling.update("wordcache", Long.valueOf(this.ram.size()), true); + cleanCache(); + } } /** @@ -272,7 +276,7 @@ public final class IndexCell extends AbstractBu private synchronized void cleanCache() { // dump the cache if necessary - if (this.ram.size() > this.maxRamEntries || (this.ram.size() > 2000 && !MemoryControl.request(100L * 1024L * 1024L, false))) { + if (this.ram.size() >= this.maxRamEntries || (this.ram.size() > 2000 && !MemoryControl.request(100L * 1024L * 1024L, false))) { try { cacheDump(); } catch (IOException e) { diff --git a/source/de/anomic/kelondro/text/ReferenceContainerCache.java b/source/de/anomic/kelondro/text/ReferenceContainerCache.java index 2cdae11d6..b20a0aa61 100644 --- a/source/de/anomic/kelondro/text/ReferenceContainerCache.java +++ b/source/de/anomic/kelondro/text/ReferenceContainerCache.java @@ -507,5 +507,5 @@ public final class ReferenceContainerCache exte public ByteOrder ordering() { return this.termOrder; } - + } diff --git a/source/de/anomic/server/serverProfiling.java b/source/de/anomic/server/serverProfiling.java index bd63361a4..acc8ebb27 100644 --- a/source/de/anomic/server/serverProfiling.java +++ b/source/de/anomic/server/serverProfiling.java @@ -35,7 +35,7 @@ import de.anomic.kelondro.util.MemoryControl; public class serverProfiling extends Thread { - private static final Map> historyMaps = new ConcurrentHashMap>(); // value=TreeMap of Long/Event + private static final Map> historyMaps = new ConcurrentHashMap>(); private static final Map eventAccess = new ConcurrentHashMap(); // value: last time when this was accessed private static serverProfiling systemProfiler = null; @@ -73,8 +73,9 @@ public class serverProfiling extends Thread { if (lastAcc == null) { eventAccess.put(eventName, Long.valueOf(System.currentTimeMillis())); } else { - if (!useProtection || System.currentTimeMillis() - lastAcc.longValue() > 1000) { - eventAccess.put(eventName, Long.valueOf(System.currentTimeMillis())); + long time = System.currentTimeMillis(); + if (!useProtection || time - lastAcc.longValue() > 1000) { + eventAccess.put(eventName, Long.valueOf(time)); } else { return; // protect against too heavy load } @@ -86,12 +87,15 @@ public class serverProfiling extends Thread { history.add(new Event(eventPayload)); // clean up too old entries - Event e; - final long now = System.currentTimeMillis(); - while (history.size() > 0) { - e = history.peek(); - if (now - e.time < 600000) break; - history.poll(); + while (history.size() > 1000) history.poll(); + if (history.size() % 10 == 0) { // reduce number of System.currentTimeMillis() calls + Event e; + final long now = System.currentTimeMillis(); + while (history.size() > 0) { + e = history.peek(); + if (now - e.time < 600000) break; + history.poll(); + } } } else { history = new ConcurrentLinkedQueue();