private static void execute(int size, Resource metric, int itr) { for (int cnt = 0; cnt < itr; cnt++) { ProblemCollection<Quad> problemCollection = new ProblemCollectionQuad(metric); long start = System.nanoTime(); for (int i = 0; i < size; i++) { Quad q = new Quad(null, new Triple(ResourceCommons.generateURI().asNode(), ResourceCommons.generateURI().asNode(), ResourceCommons.generateURI().asNode())); problemCollection.addProblem(q); } ((ProblemCollectionQuad)problemCollection).commit(); long write = System.nanoTime() - start; problemCollection.cleanup(); System.gc(); System.out.println(String.format("[%s] %s Write took %s ms, Write/tp :%s", cnt, problemCollection.getClass().getName(), TimeUnit.NANOSECONDS.toMillis(write), TimeUnit.SECONDS.toNanos(size) / write)); } }
public synchronized void commit() { if (super.isHPCEnabled) { // nothing to do here } else { if (this.totalTriples > 0) { logger.info("Commiting in-mem Model Quads to Datagraph. Metric: "+super.metricURI+". Number of triples added: "+this.totalTriples+" dataset location: "+super.location); this.totalTriples = 0; dataset.begin(ReadWrite.WRITE) ; try { dataset.addNamedModel(getNamedGraph(), this._m); dataset.commit(); } finally { dataset.end(); } this._m = null; System.gc(); this._m = ModelFactory.createDefaultModel(); } } }
@Override public void addProblem(Quad problematicElement) { this.isEmpty = false; Resource bNode = ResourceCommons.generateRDFBlankNode().asResource(); Quad q = problematicElement; this._m.add(new StatementImpl(bNode, RDF.type, RDF.Statement)); this._m.add(new StatementImpl(bNode, RDF.subject, ResourceCommons.asRDFNode(q.getSubject()))); this._m.add(new StatementImpl(bNode, RDF.predicate, ResourceCommons.asRDFNode(q.getPredicate()))); this._m.add(new StatementImpl(bNode, RDF.object, ResourceCommons.asRDFNode(q.getObject()))); if (q.getGraph() != null){ _m.add(new StatementImpl(bNode, QPRO.inGraph, ResourceCommons.asRDFNode(q.getGraph()))); } _m.add(new StatementImpl(this.problemList, RDF.li(seqCounter), ResourceCommons.asRDFNode(bNode.asNode()))); seqCounter++; totalTriples+=5; if (this.totalTriples >= MAX_TRIPLES) { this.commit(); } }