1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
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;
33 * == With WriteOnlyGraph ===
35 * -Creation of 50M write only resources (50M res, 0 stm)
37 * -UpdateTransaction off = 5.11s
38 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
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
49 * == With ClusterBuilder ==
51 * -Creation of 50M write only resources (50M res, 0 stm)
53 * -UpdateTransaction off = 5.07
54 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
56 * -UpdateTransaction off = 14.26s
57 * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
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
66 public class ReadHierarchicalNames extends ExistingDatabaseTest {
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 };
73 private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
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);
83 private void time(String label, Read<Object> request) throws DatabaseException {
85 long start = System.nanoTime();
86 getSession().syncRequest(request);
87 long duration = System.nanoTime() - start;
88 System.out.println(label + " = " + 1e-9*duration);
90 HierarchicalNames.validate();
94 private void listenTime(String label, Read<Object> request) throws DatabaseException {
96 long start = System.nanoTime();
97 getSession().syncRequest(request, new ListenerAdapter<Object>());
98 long duration = System.nanoTime() - start;
99 System.out.println(label + " = " + 1e-9*duration);
103 private void clearCaches() throws DatabaseException {
105 Session session = Tests.getTestHandler().getSession();
106 QueryControl cc = session.getService(QueryControl.class);
107 ClusterControl ccr = session.getService(ClusterControl.class);
109 ccr.collectClusters(ccr.used());
116 public void test() throws Exception {
118 Layer0.getInstance(getSession());
120 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
121 // getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
123 // System.out.println("wait");
124 // Thread.sleep(7000);
125 // System.out.println("wait done");
127 // First build the test data
128 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
130 // System.out.println("wait");
131 // Thread.sleep(3000);
132 // System.out.println("wait done");
134 // Read everything after write
135 time("response", HierarchicalNames.readAsync(root));
137 // System.out.println("wait");
138 // Thread.sleep(3000);
139 // System.out.println("wait done");
141 // Clusters are now loaded
142 time("async", HierarchicalNames.readAsync(root));
143 time("async2", HierarchicalNames.readAsync2(root));
144 // time("sync", HierarchicalNames.readSync(root));
145 // listenTime("listenSync", HierarchicalNames.readSync(root));