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