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.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.VirtualGraph;
17 import org.simantics.db.WriteOnlyGraph;
18 import org.simantics.db.common.TransactionPolicyKeep;
19 import org.simantics.db.common.WriteBindings;
20 import org.simantics.db.common.request.ReadRequest;
21 import org.simantics.db.common.request.WriteOnlyResultRequest;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.request.Read;
24 import org.simantics.db.request.WriteOnlyResult;
25 import org.simantics.db.service.TransactionPolicySupport;
26 import org.simantics.db.testing.base.ExistingDatabaseTest;
27 import org.simantics.layer0.Layer0;
29 public class WriteReadBigLiteral extends ExistingDatabaseTest {
31 private static final int _100MB = 100000000;
32 private static final int _250MB = 250000000;
33 private static final int _500MB = 500000000;
34 private static final int _1000MB = 1000000000;
35 private static final int _2000MB = 2000000000;
37 private Resource time(String label, WriteOnlyResult<Resource> request) throws DatabaseException {
39 long start = System.nanoTime();
40 Resource result = getSession().syncRequest(request);
41 long duration = System.nanoTime() - start;
42 System.out.println(label + " = " + 1e-9*duration);
47 private void time(String label, Read<Object> request) throws DatabaseException {
49 long start = System.nanoTime();
50 getSession().syncRequest(request);
51 long duration = System.nanoTime() - start;
52 System.out.println(label + " = " + 1e-9*duration);
56 public static WriteOnlyResult<Resource> writeOnly(final int size, VirtualGraph graph) throws DatabaseException {
58 final byte[] literal = new byte[size];
60 return new WriteOnlyResultRequest<Resource>(graph) {
63 public Resource perform(WriteOnlyGraph graph) throws DatabaseException {
64 Resource res = graph.newResource();
65 graph.claimValue(res, literal, WriteBindings.BYTE_ARRAY);
73 public static Read<Object> read(final Resource resource) {
75 return new ReadRequest() {
78 public void run(ReadGraph graph) throws DatabaseException {
80 byte[] value = graph.getValue(resource, WriteBindings.BYTE_ARRAY);
81 System.err.println("value: " + value.length);
89 public void test() throws Exception {
91 Layer0.getInstance(getSession());
93 getSession().registerService(TransactionPolicySupport.class, new TransactionPolicyKeep());
95 Resource root = time("write 100MB", writeOnly(_100MB, null));
96 time("response 100MB", read(root));
97 Resource root2 = time("write 250MB", writeOnly(_250MB, null));
98 time("response 250MB", read(root2));
99 Resource root3 = time("write 500MB", writeOnly(_500MB, null));
100 time("response 500MB", read(root3));
101 Resource root4 = time("write 1000MB", writeOnly(_1000MB, null));
102 time("response 1000MB", read(root4));
103 Resource root5 = time("write 2000MB", writeOnly(_2000MB, null));
104 time("response 2000MB", read(root5));
107 //// System.out.println("wait");
108 //// Thread.sleep(3000);
109 //// System.out.println("wait done");
111 // // Read everything after write
112 // time("response", HierarchicalNames.readAsync(root));
114 //// System.out.println("wait");
115 //// Thread.sleep(3000);
116 //// System.out.println("wait done");
118 // // Clusters are now loaded
119 // time("async", HierarchicalNames.readAsync(root));
120 //// time("async2", HierarchicalNames.readAsync2(root));
121 //// time("sync", HierarchicalNames.readSync(root));
122 //// listenTime("listenSync", HierarchicalNames.readSync(root));