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.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;
34 * == With WriteOnlyGraph ===
36 * -Creation of 50M write only resources (50M res, 0 stm)
38 * -UpdateTransaction off = 5.11s
39 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
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
50 * == With ClusterBuilder ==
52 * -Creation of 50M write only resources (50M res, 0 stm)
54 * -UpdateTransaction off = 5.07
55 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
57 * -UpdateTransaction off = 14.26s
58 * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
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
67 public class ReadHierarchicalNames extends ExistingDatabaseTest {
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 };
74 private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
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);
84 private void time(String label, AsyncRead<Object> request) throws DatabaseException {
86 long start = System.nanoTime();
87 getSession().syncRequest(request);
88 long duration = System.nanoTime() - start;
89 System.out.println(label + " = " + 1e-9*duration);
91 HierarchicalNames.validate();
95 private void time(String label, Read<Object> request) throws DatabaseException {
97 long start = System.nanoTime();
98 getSession().syncRequest(request);
99 long duration = System.nanoTime() - start;
100 System.out.println(label + " = " + 1e-9*duration);
102 HierarchicalNames.validate();
106 private void listenTime(String label, Read<Object> request) throws DatabaseException {
108 long start = System.nanoTime();
109 getSession().syncRequest(request, new ListenerAdapter<Object>() {
111 public boolean isDisposed() {
115 long duration = System.nanoTime() - start;
116 System.out.println(label + " = " + 1e-9*duration);
120 private void clearCaches() throws DatabaseException {
122 Session session = Tests.getTestHandler().getSession();
123 QueryControl cc = session.getService(QueryControl.class);
124 ClusterControl ccr = session.getService(ClusterControl.class);
126 ccr.collectClusters(ccr.used());
133 public void test() throws Exception {
135 Layer0.getInstance(getSession());
137 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
138 // getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
140 // System.out.println("wait");
141 // Thread.sleep(7000);
142 // System.out.println("wait done");
144 // First build the test data
145 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
147 // System.out.println("wait");
148 // Thread.sleep(3000);
149 // System.out.println("wait done");
151 // Read everything after write
152 time("response", HierarchicalNames.readAsync(root));
154 // System.out.println("wait");
155 // Thread.sleep(3000);
156 // System.out.println("wait done");
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));