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>() {
99 public boolean isDisposed() {
103 long duration = System.nanoTime() - start;
104 System.out.println(label + " = " + 1e-9*duration);
108 private void clearCaches() throws DatabaseException {
110 Session session = Tests.getTestHandler().getSession();
111 QueryControl cc = session.getService(QueryControl.class);
112 ClusterControl ccr = session.getService(ClusterControl.class);
114 ccr.collectClusters(ccr.used());
121 public void test() throws Exception {
123 Layer0.getInstance(getSession());
125 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
126 // getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
128 // System.out.println("wait");
129 // Thread.sleep(7000);
130 // System.out.println("wait done");
132 // First build the test data
133 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
135 // System.out.println("wait");
136 // Thread.sleep(3000);
137 // System.out.println("wait done");
139 // Read everything after write
140 time("response", HierarchicalNames.readAsync(root));
142 // System.out.println("wait");
143 // Thread.sleep(3000);
144 // System.out.println("wait done");
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));