]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Help investigation of query caching problems via query histogram data 10/4310/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 10 Jun 2020 18:51:12 +0000 (21:51 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 10 Jun 2020 18:59:25 +0000 (18:59 +0000)
Change-Id: I5e3d86e642e0bbe0aa50623cae0bf9e389eb3632

bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Objects.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Statements.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterBig.java
bundles/org.simantics.utils/src/org/simantics/utils/Development.java

index 0b3e1be34d3e8f16a135df845e95ebdbe4fc7ccb..b49f88c249f5215e4da11cf7186f10fd0701194e 100644 (file)
@@ -59,6 +59,9 @@ final public class Objects extends CollectionBinaryQuery<IntProcedure> {
        public final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) {
 
                if(parent == null && listener == null) {
+                       if(Development.DEVELOPMENT)
+                               Development.recordHistogram(new Objects(r1, r2).toString());
+                       
                        Objects.computeForEach(graph, r1, r2, null, procedure);
                        return;
                }
@@ -73,6 +76,9 @@ final public class Objects extends CollectionBinaryQuery<IntProcedure> {
                        entry.clearResult(processor.querySupport);
                        entry.putEntry(processor);
 
+                       if(Development.DEVELOPMENT)
+                               Development.recordHistogram(entry.toString());
+
                        processor.performForEach(graph, entry, parent, listener, procedure);
 
                } else {
index ff15d301b58214a25d20bb663889d11430008ae2..9009f8febbeb0e87c40f561355c568544a77fcc1 100644 (file)
@@ -2008,6 +2008,10 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap
                
                for(Pair<String,Integer> entry : entries) {
                        b.println(entry.first + ": " + entry.second);
+                       Exception e = Development.histogramExceptions.get(entry.first);
+                       if (e != null) {
+                               e.printStackTrace(b);
+                       }
                }
 
                b.close();
index 935b8115962df76e3672d5479521e5dba41378f3..5e9b58970ec6abc9ad1ff88f1dd42242849d48d0 100644 (file)
@@ -24,6 +24,7 @@ import org.simantics.db.impl.procedure.InternalProcedure;
 import org.simantics.db.impl.procedure.TripleIntProcedureAdapter;
 import org.simantics.db.procedure.ListenerBase;
 import org.simantics.db.request.RequestFlags;
+import org.simantics.utils.Development;
 
 final public class Statements extends CollectionBinaryQuery<TripleIntProcedure> {
        
@@ -55,6 +56,9 @@ final public class Statements extends CollectionBinaryQuery<TripleIntProcedure>
                entry.clearResult(processor.querySupport);
                entry.putEntry(processor);
                
+               if(Development.DEVELOPMENT)
+                       Development.recordHistogram(entry.toString());
+               
                processor.performForEach(graph, entry, parent, listener, procedure);
             
         } else {
@@ -83,6 +87,8 @@ final public class Statements extends CollectionBinaryQuery<TripleIntProcedure>
        assert(r2 != 0);
        
         if(parent == null && listener == null) {
+               if(Development.DEVELOPMENT)
+                       Development.recordHistogram(new Statements(r1, r2).toString());
                Statements.computeForEach(graph, r1, r2, null, procedure);
                return;
         }
index 29f34b45f9904527412db0817c0dfeb6702b2c0e..d3587f76e9a81d54aa515b31e525f824bbb83c69 100644 (file)
@@ -816,6 +816,11 @@ final public class ClusterBig extends ClusterImpl {
         throw new Error("Not supported.");
     }
 
+    @Override
+    public String toString() {
+        return "ClusterBig[" + getClusterId() + "]";
+    }
+
     public int makeResourceKey(int resourceIndex) throws DatabaseException {
         int key = 0;
 //        if (ClusterTraitsBase.isIllegalResourceIndex(resourceIndex))
index 96c3453c759020f7a8d2d072ace6af721a20b892..26359e799f0b96c460300d16896a96b57d46fc65 100644 (file)
@@ -17,9 +17,11 @@ public class Development {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(Development.class);
        public static TreeMap<String,Integer> histogram = new TreeMap<>();
+       public static Map<String, Exception> histogramExceptions = new HashMap<>();
 
        public static final boolean DEVELOPMENT = false;
-       
+       private static final int histogramExceptionThreshold = 100;
+
        public static final String PRINT = "Development.print";
 
        public interface DevelopmentListener {
@@ -98,6 +100,9 @@ public class Development {
                String key = o.toString();
                Integer i = histogram.get(key);
                histogram.put(key, i == null ? 1 : i+1);
+               if (i != null && i >= histogramExceptionThreshold) {
+                       histogramExceptions.computeIfAbsent(key, k -> new Exception());
+               }
        }
        
 }