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.simantics.db.Resource;
15 import org.simantics.db.Session;
16 import org.simantics.db.common.TransactionPolicyKeep;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.request.Read;
19 import org.simantics.db.request.WriteOnlyResult;
20 import org.simantics.db.service.QueryControl;
21 import org.simantics.db.service.TransactionPolicySupport;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23 import org.simantics.layer0.Layer0;
29 * == With WriteOnlyGraph ===
31 * -Creation of 50M write only resources (50M res, 0 stm)
33 * -UpdateTransaction off = 5.11s
34 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
36 * -UpdateTransaction off = 16.05s
37 * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
38 * -Stream off = 12.20s
39 * -UpdateTransaction off = 39.3s
40 * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
41 * -Stream off = 31.66s
42 * -Creation of 50M write only resources full (100M res, 300M stm)
43 * -Stream off = 43.39s
45 * == With ClusterBuilder ==
47 * -Creation of 50M write only resources (50M res, 0 stm)
49 * -UpdateTransaction off = 5.07
50 * -Creation of 50M write only resources with single instanceof (50M res, 50M stm)
52 * -UpdateTransaction off = 14.26s
53 * -Creation of 50M write only resources with instanceof and consists of hierarchy (50M res, 150M stm)
55 * -UpdateTransaction off = 32.42s
56 * -Creation of 50M write only resources with string name (no instanceof) (100M res, 150M stm)
57 * -Stream off = 23.97s
58 * -Creation of 50M write only resources full (100M res, 300M stm, 50M literals)
59 * -Stream off = 27.85s
62 public class ReadHierarchicalNamesAndTypes extends ExistingDatabaseTest {
64 final private static String name = "name";
65 int[] sizes = { 244, 64, 64 };
67 private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
69 long start = System.nanoTime();
70 Resource result = getSession().syncRequest(request);
71 long duration = System.nanoTime() - start;
72 System.out.println(label + " = " + 1e-9*duration);
77 private void time(String label, Read<Object> request) throws DatabaseException {
79 long start = System.nanoTime();
80 getSession().syncRequest(request);
81 long duration = System.nanoTime() - start;
82 System.out.println(label + " = " + 1e-9*duration);
86 // private void clearCaches() throws DatabaseException {
88 // Session session = Tests.getTestHandler().getSession();
89 // QueryControl cc = session.getService(QueryControl.class);
90 // ClusterControl ccr = session.getService(ClusterControl.class);
92 // ccr.collectClusters(ccr.used());
99 public void test() throws Exception {
101 Layer0.getInstance(getSession());
103 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
104 // getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyRelease());
106 // First build the test data
107 Resource root = time("write", HierarchicalNames.writeOnly(name, sizes));
109 // Read everything after write
110 time("response", HierarchicalNames.readAsyncTypes(root));
112 Session session = getSession();
113 QueryControl cc = session.getService(QueryControl.class);
116 System.out.println("wait");
118 System.out.println("wait done");
120 // Clusters are now loaded
121 time("async", HierarchicalNames.readAsyncTypes(root));
122 // System.err.println("done");
123 // time("async2", HierarchicalNames.readAsync2(root));
124 // time("sync", HierarchicalNames.readSync(root));
125 // time("sync2", HierarchicalNames.readSync2(root));