]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl.java
Merge branch 'private/db-threads' into private/threads-testing
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / QueryCollectorImpl.java
index 965f1e39f41fb1dc4d99000d533c03dde6c21da3..8ea760b75c4a8774a2454f6b2393aed8a388975d 100644 (file)
@@ -29,10 +29,11 @@ class QueryCollectorImpl implements QueryProcessor.QueryCollector {
         */
        boolean propagate = true;
        
-       
        private static final int COLLECT_N = 1000;
        
+       private long allowance = 100;
        private long spent = 0;
+       private long collectionCounter = 0;
        
        QueryCollectorImpl(QueryProcessor queryProcessor, QueryCollectorSupport support) {
                this.queryProcessor = queryProcessor;
@@ -41,14 +42,28 @@ class QueryCollectorImpl implements QueryProcessor.QueryCollector {
        
        @Override
        public void collect(int youngTarget, int allowedTimeInMs) {
-
+               
                long start = System.nanoTime();
 
                // Refresh current size
                int size = support.calculateCurrentSize();
+               
+//             if(collectionCounter > allowance) {
+//                     collectionCounter = 0;
+//                     allowance = (allowance * 1100) / 1000;
+//             }
+               
                int bound = queryProcessor.boundQueries;
                int young = size - bound;
                int youngPct = size > 0 ? 100*young / size : 0;
+
+               // System.err.println("Collect size = " + size + " bound=" + bound + " allowance=" + allowance);
+               
+               // Allowance maintains a reasonable set of queries 
+               if(size < allowance) return;
+               
+               // No need to collect anything if the amount of free queries is small compared to the amount of bound queries
+               if(youngPct < youngTarget) return;
                
                // Initialize support for new run
                // If support returns 0 we are starting from 0
@@ -182,6 +197,7 @@ class QueryCollectorImpl implements QueryProcessor.QueryCollector {
                                support.remove();
                                propagate = true;
                                moreAll++;
+                               collectionCounter++;
                                doneAll = false;
                                return true;
                        }