]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNames.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / ReadHierarchicalNames.java
diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNames.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNames.java
new file mode 100644 (file)
index 0000000..974cc71
--- /dev/null
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.performance.read;
+
+import org.junit.Test;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.common.TransactionPolicyKeep;
+import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.db.request.WriteOnlyResult;
+import org.simantics.db.service.ClusterControl;
+import org.simantics.db.service.QueryControl;
+import org.simantics.db.service.TransactionPolicySupport;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.db.testing.common.Tests;
+import org.simantics.layer0.Layer0;
+
+/*
+ *
+ * Some statistics:
+ *
+ * == With WriteOnlyGraph ===
+ *
+ * -Creation of 50M write only resources (50M res, 0 stm)
+ *  -Stream off = 1.88s
+ *  -UpdateTransaction off = 5.11s
+ * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
+ *  -Stream off = 5.36s
+ *  -UpdateTransaction off = 16.05s
+ * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
+ *  -Stream off = 12.20s
+ *  -UpdateTransaction off = 39.3s
+ * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
+ *  -Stream off = 31.66s
+ * -Creation of 50M write only resources full (100M res, 300M stm)
+ *  -Stream off = 43.39s
+ *
+ * == With ClusterBuilder ==
+ *
+ * -Creation of 50M write only resources (50M res, 0 stm)
+ *  -Stream off = 1.62s
+ *  -UpdateTransaction off = 5.07
+ * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
+ *  -Stream off = 3.33s
+ *  -UpdateTransaction off = 14.26s
+ * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
+ *  -Stream off = 6.09s
+ *  -UpdateTransaction off = 32.42s
+ * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
+ *  -Stream off = 23.97s
+ * -Creation of 50M write only resources full (100M res, 300M stm, 50M literals)
+ *  -Stream off = 27.85s
+ *
+ */
+public class ReadHierarchicalNames extends ExistingDatabaseTest {
+
+       final private static String name = "name";
+//     int[] sizes = { 2, 2, 2 };
+//     int[] sizes = { 3, 2, 5 };
+       int[] sizes = { 2*122, 64, 64 };
+
+       private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
+
+               long start = System.nanoTime();
+               Resource result = getSession().syncRequest(request);
+               long duration = System.nanoTime() - start;
+               System.out.println(label + " = " + 1e-9*duration);
+               return result;
+
+       }
+
+       private void time(String label, Read<Object> request) throws DatabaseException {
+
+               long start = System.nanoTime();
+               getSession().syncRequest(request);
+               long duration = System.nanoTime() - start;
+               System.out.println(label + " = " + 1e-9*duration);
+
+               HierarchicalNames.validate();
+
+       }
+
+       private void listenTime(String label, Read<Object> request) throws DatabaseException {
+
+               long start = System.nanoTime();
+               getSession().syncRequest(request, new ListenerAdapter<Object>());
+               long duration = System.nanoTime() - start;
+               System.out.println(label + " = " + 1e-9*duration);
+
+       }
+
+       private void clearCaches() throws DatabaseException {
+
+               Session session = Tests.getTestHandler().getSession();
+               QueryControl cc = session.getService(QueryControl.class);
+               ClusterControl ccr = session.getService(ClusterControl.class);
+               cc.flush();
+               ccr.collectClusters(ccr.used());
+               System.gc();
+               System.gc();
+               System.gc();
+
+       }
+       @Test
+       public void test() throws Exception {
+
+               Layer0.getInstance(getSession());
+
+               getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
+//             getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
+
+//             System.out.println("wait");
+//             Thread.sleep(7000);
+//             System.out.println("wait done");
+
+               // First build the test data
+               Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
+
+//             System.out.println("wait");
+//             Thread.sleep(3000);
+//             System.out.println("wait done");
+
+               // Read everything after write
+               time("response", HierarchicalNames.readAsync(root));
+
+//             System.out.println("wait");
+//             Thread.sleep(3000);
+//             System.out.println("wait done");
+
+               // Clusters are now loaded
+               time("async", HierarchicalNames.readAsync(root));
+               time("async2", HierarchicalNames.readAsync2(root));
+//             time("sync", HierarchicalNames.readSync(root));
+//             listenTime("listenSync", HierarchicalNames.readSync(root));
+
+       }
+
+}