]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/ReadHierarchicalNames.java
66e3842e0df12305071307a8891875f27605d588
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / ReadHierarchicalNames.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.junit.Test;
15 import org.simantics.db.Resource;
16 import org.simantics.db.Session;
17 import org.simantics.db.common.TransactionPolicyKeep;
18 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.request.Read;
21 import org.simantics.db.request.WriteOnlyResult;
22 import org.simantics.db.service.ClusterControl;
23 import org.simantics.db.service.QueryControl;
24 import org.simantics.db.service.TransactionPolicySupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26 import org.simantics.db.testing.common.Tests;
27 import org.simantics.layer0.Layer0;
28
29 /*
30  *
31  * Some statistics:
32  *
33  * == With WriteOnlyGraph ===
34  *
35  * -Creation of 50M write only resources (50M res, 0 stm)
36  *  -Stream off = 1.88s
37  *  -UpdateTransaction off = 5.11s
38  * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
39  *  -Stream off = 5.36s
40  *  -UpdateTransaction off = 16.05s
41  * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
42  *  -Stream off = 12.20s
43  *  -UpdateTransaction off = 39.3s
44  * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
45  *  -Stream off = 31.66s
46  * -Creation of 50M write only resources full (100M res, 300M stm)
47  *  -Stream off = 43.39s
48  *
49  * == With ClusterBuilder ==
50  *
51  * -Creation of 50M write only resources (50M res, 0 stm)
52  *  -Stream off = 1.62s
53  *  -UpdateTransaction off = 5.07
54  * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
55  *  -Stream off = 3.33s
56  *  -UpdateTransaction off = 14.26s
57  * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
58  *  -Stream off = 6.09s
59  *  -UpdateTransaction off = 32.42s
60  * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
61  *  -Stream off = 23.97s
62  * -Creation of 50M write only resources full (100M res, 300M stm, 50M literals)
63  *  -Stream off = 27.85s
64  *
65  */
66 public class ReadHierarchicalNames extends ExistingDatabaseTest {
67
68         final private static String name = "name";
69 //      int[] sizes = { 2, 2, 2 };
70 //      int[] sizes = { 3, 2, 5 };
71         int[] sizes = { 2*122, 64, 64 };
72
73         private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
74
75                 long start = System.nanoTime();
76                 Resource result = getSession().syncRequest(request);
77                 long duration = System.nanoTime() - start;
78                 System.out.println(label + " = " + 1e-9*duration);
79                 return result;
80
81         }
82
83         private void time(String label, Read<Object> request) throws DatabaseException {
84
85                 long start = System.nanoTime();
86                 getSession().syncRequest(request);
87                 long duration = System.nanoTime() - start;
88                 System.out.println(label + " = " + 1e-9*duration);
89
90                 HierarchicalNames.validate();
91
92         }
93
94         private void listenTime(String label, Read<Object> request) throws DatabaseException {
95
96                 long start = System.nanoTime();
97                 getSession().syncRequest(request, new ListenerAdapter<Object>() {
98                         @Override
99                         public boolean isDisposed() {
100                                 return false;
101                         }
102                 });
103                 long duration = System.nanoTime() - start;
104                 System.out.println(label + " = " + 1e-9*duration);
105
106         }
107
108         private void clearCaches() throws DatabaseException {
109
110                 Session session = Tests.getTestHandler().getSession();
111                 QueryControl cc = session.getService(QueryControl.class);
112                 ClusterControl ccr = session.getService(ClusterControl.class);
113                 cc.flush();
114                 ccr.collectClusters(ccr.used());
115                 System.gc();
116                 System.gc();
117                 System.gc();
118
119         }
120         @Test
121         public void test() throws Exception {
122
123                 Layer0.getInstance(getSession());
124
125                 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
126 //              getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
127
128 //              System.out.println("wait");
129 //              Thread.sleep(7000);
130 //              System.out.println("wait done");
131
132                 // First build the test data
133                 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
134
135 //              System.out.println("wait");
136 //              Thread.sleep(3000);
137 //              System.out.println("wait done");
138
139                 // Read everything after write
140                 time("response", HierarchicalNames.readAsync(root));
141
142 //              System.out.println("wait");
143 //              Thread.sleep(3000);
144 //              System.out.println("wait done");
145
146                 // Clusters are now loaded
147                 time("async", HierarchicalNames.readAsync(root));
148                 time("async2", HierarchicalNames.readAsync2(root));
149 //              time("sync", HierarchicalNames.readSync(root));
150 //              listenTime("listenSync", HierarchicalNames.readSync(root));
151
152         }
153
154 }