]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNamesAndTypes.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 / ReadHierarchicalNamesAndTypes.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
13
14 import org.simantics.db.Resource;
15 import org.simantics.db.Session;
16 import org.simantics.db.common.TransactionPolicyKeep;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.request.Read;
19 import org.simantics.db.request.WriteOnlyResult;
20 import org.simantics.db.service.QueryControl;
21 import org.simantics.db.service.TransactionPolicySupport;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23 import org.simantics.layer0.Layer0;
24
25 /*
26  *
27  * Some statistics:
28  *
29  * == With WriteOnlyGraph ===
30  *
31  * -Creation of 50M write only resources (50M res, 0 stm)
32  *  -Stream off = 1.88s
33  *  -UpdateTransaction off = 5.11s
34  * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
35  *  -Stream off = 5.36s
36  *  -UpdateTransaction off = 16.05s
37  * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
38  *  -Stream off = 12.20s
39  *  -UpdateTransaction off = 39.3s
40  * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
41  *  -Stream off = 31.66s
42  * -Creation of 50M write only resources full (100M res, 300M stm)
43  *  -Stream off = 43.39s
44  *
45  * == With ClusterBuilder ==
46  *
47  * -Creation of 50M write only resources (50M res, 0 stm)
48  *  -Stream off = 1.62s
49  *  -UpdateTransaction off = 5.07
50  * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
51  *  -Stream off = 3.33s
52  *  -UpdateTransaction off = 14.26s
53  * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
54  *  -Stream off = 6.09s
55  *  -UpdateTransaction off = 32.42s
56  * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
57  *  -Stream off = 23.97s
58  * -Creation of 50M write only resources full (100M res, 300M stm, 50M literals)
59  *  -Stream off = 27.85s
60  *
61  */
62 public class ReadHierarchicalNamesAndTypes extends ExistingDatabaseTest {
63
64         final private static String name = "name";
65         int[] sizes = { 244, 64, 64 };
66
67         private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
68
69                 long start = System.nanoTime();
70                 Resource result = getSession().syncRequest(request);
71                 long duration = System.nanoTime() - start;
72                 System.out.println(label + " = " + 1e-9*duration);
73                 return result;
74
75         }
76
77         private void time(String label, Read<Object> request) throws DatabaseException {
78
79                 long start = System.nanoTime();
80                 getSession().syncRequest(request);
81                 long duration = System.nanoTime() - start;
82                 System.out.println(label + " = " + 1e-9*duration);
83
84         }
85
86 //      private void clearCaches() throws DatabaseException {
87 //
88 //              Session session = Tests.getTestHandler().getSession();
89 //              QueryControl cc = session.getService(QueryControl.class);
90 //              ClusterControl ccr = session.getService(ClusterControl.class);
91 //              cc.flush();
92 //              ccr.collectClusters(ccr.used());
93 //              System.gc();
94 //              System.gc();
95 //              System.gc();
96 //
97 //      }
98
99         public void test() throws Exception {
100
101                 Layer0.getInstance(getSession());
102
103                 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
104 //              getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
105
106                 // First build the test data
107                 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
108
109                 // Read everything after write
110                 time("response", HierarchicalNames.readAsyncTypes(root));
111
112                 Session session = getSession();
113                 QueryControl cc = session.getService(QueryControl.class);
114                 cc.flush();
115
116                 System.out.println("wait");
117                 Thread.sleep(3000);
118                 System.out.println("wait done");
119
120                 // Clusters are now loaded
121                 time("async", HierarchicalNames.readAsyncTypes(root));
122 //              System.err.println("done");
123 //              time("async2", HierarchicalNames.readAsync2(root));
124 //              time("sync", HierarchicalNames.readSync(root));
125 //              time("sync2", HierarchicalNames.readSync2(root));
126
127         }
128
129 }