Author: andy
Date: Fri Jun 15 09:23:46 2012
New Revision: 1350547

URL: http://svn.apache.org/viewvc?rev=1350547&view=rev
Log: (empty)

Added:
    jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena256_TDBWritePerf.java

Added: jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena256_TDBWritePerf.java
URL: 
http://svn.apache.org/viewvc/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena256_TDBWritePerf.java?rev=1350547&view=auto
==============================================================================
--- jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena256_TDBWritePerf.java (added)
+++ jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena256_TDBWritePerf.java Fri Jun 
15 09:23:46 2012
@@ -0,0 +1,107 @@
+
+/* Original version: */
+/* 
******************************************************************************
+ * Licensed Materials - Property of IBM
+ * (c) Copyright IBM Corporation 2011. All Rights Reserved.
+ *
+ * Note to U.S. Government Users Restricted Rights:  Use,
+ * duplication or disclosure restricted by GSA ADP Schedule
+ * Contract with IBM Corp.
+ * 
*****************************************************************************/
+
+
+package dev ;
+
+import java.util.ArrayList ;
+import java.util.List ;
+
+import org.openjena.atlas.lib.FileOps ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.ReadWrite ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.Property ;
+import com.hp.hpl.jena.rdf.model.Resource ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.base.block.FileMode ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
+
+public class Jena256_TDBWritePerf {
+
+       private final static int TOTAL = 100;
+       final static String INDEX_INFO_SUBJECT = 
"http://test.net/xmlns/test/1.0/Triple-Indexer";;
+       final static String TIMESTAMP_PREDICATE = 
"http://test.net/xmlns/test/1.0/lastProcessedTimestamp";;
+       final static String URI_PREDICATE = 
"http://test.net/xmlns/test/1.0/lastProcessedUri";;
+       final static String VERSION_PREDICATE = 
"http://test.net/xmlns/test/1.0/indexVersion";;
+       final static String INDEX_SIZE_PREDICATE = 
"http://test.net/xmlns/test/1.0/indexSize";;
+
+       /**
+        * @param args
+        */
+       public static void main(String[] args) {
+
+//             if (args.length == 0) {
+//                     System.out.println("Provide index location");
+//                     return;
+//             }
+
+           String location = "DBX" ;
+           FileOps.ensureDir(location) ;
+           FileOps.clearDirectory(location) ;
+           
+           //Submitted without .... 
+           if ( false )
+               SystemTDB.setFileMode(FileMode.direct) ;
+           
+           //String location = args[0]; // + "/" + 
UUID.randomUUID().toString();
+
+               String baseGraphName = "com.ibm.test.graphNamePrefix.";
+
+               long totalExecTime = 0L;
+               long size = 0;
+               for (int i = 0; i < TOTAL; i++) {
+                       List<String> lastProcessedUris = new 
ArrayList<String>();
+                       for (int j = 0; j < i; j++) {
+                               String lastProcessedUri = 
"http://test.net/xmlns/test/1.0/someUri"; + j;
+                               lastProcessedUris.add(lastProcessedUri);
+                       }
+                       Dataset dataset = TDBFactory.createDataset(location);
+                       String graphName = baseGraphName + i;
+                       long t = System.currentTimeMillis();
+
+                       try {
+                               dataset.begin(ReadWrite.WRITE);
+                               Model m = dataset.getNamedModel(graphName);
+
+                               m.removeAll();
+                               Resource subject = 
m.createResource(INDEX_INFO_SUBJECT);
+                               Property predicate = 
m.createProperty(TIMESTAMP_PREDICATE);
+                               m.addLiteral(subject, predicate, 
System.currentTimeMillis());
+                               predicate = m.createProperty(URI_PREDICATE);
+                               for (String uri : lastProcessedUris) {
+                                       m.add(subject, predicate, 
m.createResource(uri));
+                               }
+                               predicate = m.createProperty(VERSION_PREDICATE);
+                               m.addLiteral(subject, predicate, 1.0);
+
+                               size += m.size() + 1;
+
+                               predicate = 
m.createProperty(INDEX_SIZE_PREDICATE);
+                               m.addLiteral(subject, predicate, size);
+
+                               dataset.commit();
+                       } catch (Throwable e) {
+                               dataset.abort();
+                               throw new RuntimeException(e);
+                       } finally {
+                               dataset.end();
+                               long writeOperationDuration = 
System.currentTimeMillis() - t;
+                               totalExecTime += writeOperationDuration;
+                               System.out.println("Write operation " + i + " 
took " + writeOperationDuration + "ms");
+                       }
+               }
+
+               System.out.println("All " + TOTAL + " write operations wrote " 
+ size + " triples and took " + totalExecTime + "ms");
+       }
+
+}


Reply via email to