X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2FQueryMemoryWatcher.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2FQueryMemoryWatcher.java;h=23e5982316549942d68e32646259d594177942c3;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=178177a1f2bdfb348c15c999b6e45afe185e4821;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/QueryMemoryWatcher.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/QueryMemoryWatcher.java index 178177a1f..23e598231 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/QueryMemoryWatcher.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/QueryMemoryWatcher.java @@ -1,46 +1,46 @@ -package org.simantics.db.common; - -import org.simantics.db.ReadGraph; -import org.simantics.db.service.QueryControl; - -public class QueryMemoryWatcher { - - final ReadGraph graph; - final QueryControl support; - final int stopTime; - final long baseline; - final long highLimit; - final long lowLimit; - boolean collecting = false; - - public QueryMemoryWatcher(ReadGraph graph, int allowedQueries) { - this(graph, allowedQueries, 0.5, 10); - } - - public QueryMemoryWatcher(ReadGraph graph, int allowedQueries, double ratio, int stopTime) { - this.support = graph.getService(QueryControl.class); - baseline = support.count(); - highLimit = baseline + allowedQueries; - lowLimit = baseline + (int)(allowedQueries*ratio); - this.graph = graph; - this.stopTime = 10; - //System.err.println("QueryMemoryWatcher started with " + baseline + " queries."); - } - - public void maintain() { - long current = support.count(); - if(collecting) { - if(current > lowLimit) support.gc(graph, stopTime); - else { -// System.err.println("QueryMemoryWatcher stops collecting"); - collecting = false; - } - } else { - if(current > highLimit) { -// System.err.println("QueryMemoryWatcher starts collecting"); - collecting = true; - } - } - } - -} +package org.simantics.db.common; + +import org.simantics.db.ReadGraph; +import org.simantics.db.service.QueryControl; + +public class QueryMemoryWatcher { + + final ReadGraph graph; + final QueryControl support; + final int stopTime; + final long baseline; + final long highLimit; + final long lowLimit; + boolean collecting = false; + + public QueryMemoryWatcher(ReadGraph graph, int allowedQueries) { + this(graph, allowedQueries, 0.5, 10); + } + + public QueryMemoryWatcher(ReadGraph graph, int allowedQueries, double ratio, int stopTime) { + this.support = graph.getService(QueryControl.class); + baseline = support.count(); + highLimit = baseline + allowedQueries; + lowLimit = baseline + (int)(allowedQueries*ratio); + this.graph = graph; + this.stopTime = 10; + //System.err.println("QueryMemoryWatcher started with " + baseline + " queries."); + } + + public void maintain() { + long current = support.count(); + if(collecting) { + if(current > lowLimit) support.gc(graph, stopTime); + else { +// System.err.println("QueryMemoryWatcher stops collecting"); + collecting = false; + } + } else { + if(current > highLimit) { +// System.err.println("QueryMemoryWatcher starts collecting"); + collecting = true; + } + } + } + +}