Java Code Examples for org.apache.commons.lang3.time.StopWatch#reset()

The following examples show how to use org.apache.commons.lang3.time.StopWatch#reset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KMeansTest.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testPerformanceAllIterations() {
    Nd4j.setDefaultDataTypes(DataType.DOUBLE, DataType.DOUBLE);
    Nd4j.getRandom().setSeed(7);
    int numClusters = 20;
    for (boolean mode : useKMeansPlusPlus) {
        StopWatch watch = new StopWatch();
        watch.start();
        KMeansClustering kMeansClustering = KMeansClustering.setup(numClusters, 1000, Distance.COSINE_DISTANCE, mode);
        List<Point> points = Point.toPoints(Nd4j.linspace(0, 5000 * 300, 5000 * 300).reshape(5000, 300));

        ClusterSet clusterSet = kMeansClustering.applyTo(points);
        watch.stop();
        System.out.println("Elapsed for clustering : " + watch);

        watch.reset();
        watch.start();
        for (Point p : points) {
            PointClassification pointClassification = clusterSet.classifyPoint(p);
        }
        watch.stop();
        System.out.println("Elapsed for search: " + watch);
    }
}
 
Example 2
Source File: TestBatch.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testInsertUpdateQuotedStrings() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().normalBatchModeOn();
    for (int i = 0; i < 100; i++) {
        this.sqlgGraph.addVertex(T.label, "Person", "name", "'a'");
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    this.sqlgGraph.tx().normalBatchModeOn();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().toList();
    for (Vertex v : vertices) {
        v.property("name", "'b'");
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 3
Source File: IndyRepositorySession.java    From pnc with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteBuildGroup() throws RepositoryManagerException {
    logger.info("BEGIN: Removing build aggregation group: {}", buildContentId);
    userLog.info("Removing build aggregation group");
    StopWatch stopWatch = StopWatch.createStarted();

    try {
        StoreKey key = new StoreKey(packageType, StoreType.group, buildContentId);
        serviceAccountIndy.stores().delete(key, "[Post-Build] Removing build aggregation group: " + buildContentId);
    } catch (IndyClientException e) {
        throw new RepositoryManagerException(
                "Failed to retrieve Indy stores module. Reason: %s",
                e,
                e.getMessage());
    }
    logger.info(
            "END: Removing build aggregation group: {}, took: {} seconds",
            buildContentId,
            stopWatch.getTime(TimeUnit.SECONDS));
    stopWatch.reset();
}
 
Example 4
Source File: TestCellBlockBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
private static void timerTests(final CellBlockBuilder builder, final int count, final int size,
    final Codec codec, final CompressionCodec compressor) throws IOException {
  final int cycles = 1000;
  StopWatch timer = new StopWatch();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(builder, timer, count, size, codec, compressor, false);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false + ", count="
      + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
  timer.reset();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(builder, timer, count, size, codec, compressor, true);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true + ", count="
      + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
}
 
Example 5
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinVertexCompileStep() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    List<String> uuids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String uuid = UUID.randomUUID().toString();
        uuids.add(uuid);
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", uuid);
        god.addEdge("creator", person);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinVertexCompileStep_assert(this.sqlgGraph, god, uuids);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinVertexCompileStep_assert(this.sqlgGraph1, god, uuids);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());

}
 
Example 6
Source File: TestBulkWithin.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinWithPercentageInJoinProperties() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    List<String> uuids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String uuid = UUID.randomUUID().toString();
        uuids.add("\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", "\"BLRNC5->CXC4030052~%%%~FAJ1211373~%%%~2015-07-19~%%%~9999-12-31~%%%~Enabled~%%%~Licensed~%%%~Improved~%%%~compressed~%%%~mode~%%%~handling.~%%%~Restricted:~%%%~\"\"Partial.~%%%~Feature~%%%~is~%%%~restricted~%%%~in~%%%~RNC~%%%~W12B~%%%~SW.~%%%~RNC~%%%~W13.0.1.1~%%%~or~%%%~later~%%%~SW~%%%~is~%%%~required~%%%~in~%%%~order~%%%~to~%%%~run~%%%~this~%%%~feature.~%%%~For~%%%~RBS~%%%~W12.1.2.2/~%%%~W13.0.0.0~%%%~or~%%%~later~%%%~is~%%%~required.~%%%~OSS-RC~%%%~12.2~%%%~or~%%%~later~%%%~is~%%%~required.\"\".~%%%~GA:~%%%~W13A\"" + uuid);
        god.addEdge("creator", person);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph, uuids);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinWithPercentageInJoinProperties_assert(this.sqlgGraph1, uuids);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 7
Source File: TestBulkWithout.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithout() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    List<String> uuids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String uuid = UUID.randomUUID().toString();
        uuids.add(uuid);
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", uuid);
        god.addEdge("creator", person);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithout_assert(this.sqlgGraph, uuids);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithout_assert(this.sqlgGraph1, uuids);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 8
Source File: TestBulkWithout.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinMultipleHasContainers() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 1, "name", "pete");
    god.addEdge("creator", person1);
    Vertex person2 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 2, "name", "pete");
    god.addEdge("creator", person2);
    Vertex person3 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 3, "name", "john");
    god.addEdge("creator", person3);
    Vertex person4 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 4, "name", "pete");
    god.addEdge("creator", person4);
    Vertex person5 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 5, "name", "pete");
    god.addEdge("creator", person5);
    Vertex person6 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 6, "name", "pete");
    god.addEdge("creator", person6);
    Vertex person7 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 7, "name", "pete");
    god.addEdge("creator", person7);
    Vertex person8 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 8, "name", "pete");
    god.addEdge("creator", person8);
    Vertex person9 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 9, "name", "pete");
    god.addEdge("creator", person9);
    Vertex person10 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 10, "name", "pete");
    god.addEdge("creator", person10);

    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinMultipleHasContainers_assert(this.sqlgGraph);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinMultipleHasContainers_assert(this.sqlgGraph1);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 9
Source File: TestBulkWithout.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testBulkWithinVertexCompileStep() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    List<String> uuids = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        String uuid = UUID.randomUUID().toString();
        uuids.add(uuid);
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", uuid);
        god.addEdge("creator", person);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinVertexCompileStep_assert(this.sqlgGraph, god, uuids);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinVertexCompileStep_assert(this.sqlgGraph1, god, uuids);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());

}
 
Example 10
Source File: GlobalCharacterizer.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Map<String, Double> characterize(final Instances instances) {

	if (this.logger.isTraceEnabled()) {
		this.logger.trace("Characterize dataset \"{}\" ...", instances.relationName());
	}

	TreeMap<String, Double> metaFeatures = new TreeMap<>();
	StopWatch watch = new StopWatch();

	for (Characterizer characterizer : this.characterizers) {
		try {
			watch.reset();
			watch.start();
			metaFeatures.putAll(characterizer.characterize(instances));
			watch.stop();
			this.computationTimes.put(characterizer.toString(), (double) watch.getTime());
		} catch (Exception e) {
			for (String metaFeature : characterizer.getIDs()) {
				metaFeatures.put(metaFeature, Double.NaN);
			}
			this.computationTimes.put(characterizer.toString(), Double.NaN);
		}
	}

	this.logger.trace("Done characterizing dataset. Feature length: {}", metaFeatures.size());

	return metaFeatures;
}
 
Example 11
Source File: TestBatch.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testPerformance() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().normalBatchModeOn();
    for (int i = 0; i < 10000; i++) {
        Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko" + i);
        Vertex spaceTime = this.sqlgGraph.addVertex(T.label, "SpaceTime", "name", "marko" + i);
        Vertex space = this.sqlgGraph.addVertex(T.label, "Space", "name", "marko" + i);
        Vertex time = this.sqlgGraph.addVertex(T.label, "Time", "name", "marko" + i);
        person.addEdge("spaceTime", spaceTime, "context", 1);
        spaceTime.addEdge("space", space, "dimension", 3);
        spaceTime.addEdge("time", time, "dimension", 1);
        if (i != 0 && i % 10000 == 0) {
            this.sqlgGraph.tx().commit();
            this.sqlgGraph.tx().normalBatchModeOn();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testPerformance_assert(this.sqlgGraph);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(1000);
        testPerformance_assert(this.sqlgGraph1);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 12
Source File: SlimFixture.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
private int getNextInterval(StopWatch loopTimer) {
    int nextInterval;
    long loopTime = loopTimer.getTime();
    nextInterval = Math.max(0, ((int) (repeatInterval - loopTime)));
    loopTimer.reset();
    return nextInterval;
}
 
Example 13
Source File: TestBatchServerSideEdgeCreation.java    From sqlg with MIT License 4 votes vote down vote up
@Test
public void testBulkEdges2() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().streamingBatchModeOn();
    List<Pair<String, String>> uids = new ArrayList<>();
    LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
    String uuid1Cache = null;
    String uuid2Cache = null;
    for (int i = 0; i < 1000; i++) {
        String uuid1 = UUID.randomUUID().toString();
        String uuid2 = UUID.randomUUID().toString();
        if (i == 50) {
            uuid1Cache = uuid1;
            uuid2Cache = uuid2;
        }
        uids.add(Pair.of(uuid1, uuid2));
        properties.put("id", uuid1);
        this.sqlgGraph.streamVertex("Person", properties);
        properties.put("id", uuid2);
        this.sqlgGraph.streamVertex("Person", properties);
    }
    this.sqlgGraph.tx().flush();
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();

    this.sqlgGraph.tx().streamingBatchModeOn();
    SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "Person");
    this.sqlgGraph.bulkAddEdges("Person", "Person", "friend", Pair.of("id", "id"), uids);
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());

    testBulkEdges2_assert(this.sqlgGraph, uuid1Cache, uuid2Cache);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkEdges2_assert(this.sqlgGraph1, uuid1Cache, uuid2Cache);
    }
}
 
Example 14
Source File: TsneTest.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Ignore
@Test
public void testTSNEPerformance() throws Exception {

        for (WorkspaceMode wsm : new WorkspaceMode[]{WorkspaceMode.NONE, WorkspaceMode.ENABLED}) {

            //STEP 1: Initialization
            int iterations = 50;
            //create an n-dimensional array of doubles
            Nd4j.setDataType(DataType.DOUBLE);
            List<String> cacheList = new ArrayList<>(); //cacheList is a dynamic array of strings used to hold all words

            //STEP 2: Turn text input into a list of words
            INDArray weights = Nd4j.rand(10000,300);

            StopWatch watch = new StopWatch();
            watch.start();
            //STEP 3: build a dual-tree tsne to use later
            log.info("Build model....");
            BarnesHutTsne tsne = new BarnesHutTsne.Builder()
                    .setMaxIter(iterations)
                    .theta(0.5)
                    .normalize(false)
                    .learningRate(500)
                    .useAdaGrad(false)
                    .workspaceMode(wsm)
                    .build();

            watch.stop();
            System.out.println("Elapsed time for construction: " + watch);

            //STEP 4: establish the tsne values and save them to a file
            log.info("Store TSNE Coordinates for Plotting....");
            File outDir = testDir.newFolder();

            watch.reset();
            watch.start();
            tsne.fit(weights);
            watch.stop();
            System.out.println("Elapsed time for fit: " + watch);
            tsne.saveAsFile(cacheList, new File(outDir, "out.txt").getAbsolutePath());
        }
}
 
Example 15
Source File: EntityCollectionManagerStressTest.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Test
public void writeThousands() {

    ApplicationScope context = new ApplicationScopeImpl(new SimpleId("organization"));

    EntityCollectionManager manager = factory.createCollectionManager(context);

    int limit = 10000;

    StopWatch timer = new StopWatch();
    timer.start();
    Set<Id> ids = new HashSet<Id>();
    for (int i = 0; i < limit; i++) {

        Entity newEntity = new Entity(new SimpleId("test"));
        newEntity.setField(new StringField("name", String.valueOf(i)));
        newEntity.setField(new LocationField("location", new Location(120,40)));

        Entity returned = manager.write(newEntity, null ).toBlocking().last();

        assertNotNull("Returned has a id", returned.getId());
        assertNotNull("Returned has a version", returned.getVersion());

        ids.add(returned.getId());

        if ( i % 1000 == 0 ) {
            logger.info("   Wrote: " + i);
        }
    }
    timer.stop();
    logger.info( "Total time to write {} entries {}ms", limit, timer.getTime());
    timer.reset();

    timer.start();
    for ( Id id : ids ) {
        Entity entity = manager.load( id ).toBlocking().last();
        assertNotNull("Returned has a id", entity.getId());
        assertNotNull("Returned has a version", entity.getVersion());
    }
    timer.stop();
    logger.info( "Total time to read {} entries {}ms", limit, timer.getTime());
}
 
Example 16
Source File: SecuritySynchronization.java    From archiva with Apache License 2.0 4 votes vote down vote up
private void executeEnvironmentChecks()
    throws ArchivaException
{
    if ( ( checkers == null ) || CollectionUtils.isEmpty( checkers.values() ) )
    {
        throw new ArchivaException(
            "Unable to initialize the Redback Security Environment, " + "no Environment Check components found." );
    }

    StopWatch stopWatch = new StopWatch();
    stopWatch.reset();
    stopWatch.start();

    List<String> violations = new ArrayList<>();

    for ( Entry<String, EnvironmentCheck> entry : checkers.entrySet() )
    {
        EnvironmentCheck check = entry.getValue();
        List<String> v = new ArrayList<>();
        check.validateEnvironment( v );
        log.info( "Environment Check: {} -> {} violation(s)", entry.getKey(), v.size() );
        for ( String s : v )
        {
            violations.add( "[" + entry.getKey() + "] " + s );
        }
    }

    if ( CollectionUtils.isNotEmpty( violations ) )
    {
        StringBuilder msg = new StringBuilder();
        msg.append( "EnvironmentCheck Failure.\n" );
        msg.append( "======================================================================\n" );
        msg.append( " ENVIRONMENT FAILURE !! \n" );
        msg.append( "\n" );

        for ( String violation : violations )
        {
            msg.append( violation ).append( "\n" );
        }

        msg.append( "\n" );
        msg.append( "======================================================================" );
        log.error( msg.toString() );

        throw new ArchivaException( "Unable to initialize Redback Security Environment, [" + violations.size()
                                        + "] violation(s) encountered, See log for details." );
    }

    stopWatch.stop();
    log.info( "time to execute all EnvironmentCheck: {} ms", stopWatch.getTime() );
}
 
Example 17
Source File: TestBulkWithin.java    From sqlg with MIT License 4 votes vote down vote up
@Test
public void testBulkWithinMultipleHasContainers() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().normalBatchModeOn();
    }
    Vertex god = this.sqlgGraph.addVertex(T.label, "God");
    Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 1, "name", "pete");
    god.addEdge("creator", person1);
    Vertex person2 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 2, "name", "pete");
    god.addEdge("creator", person2);
    Vertex person3 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 3, "name", "john");
    god.addEdge("creator", person3);
    Vertex person4 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 4, "name", "pete");
    god.addEdge("creator", person4);
    Vertex person5 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 5, "name", "pete");
    god.addEdge("creator", person5);
    Vertex person6 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 6, "name", "pete");
    god.addEdge("creator", person6);
    Vertex person7 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 7, "name", "pete");
    god.addEdge("creator", person7);
    Vertex person8 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 8, "name", "pete");
    god.addEdge("creator", person8);
    Vertex person9 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 9, "name", "pete");
    god.addEdge("creator", person9);
    Vertex person10 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 10, "name", "pete");
    god.addEdge("creator", person10);

    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    testBulkWithinMultipleHasContrainers_assert(this.sqlgGraph);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkWithinMultipleHasContrainers_assert(this.sqlgGraph);
    }
    stopWatch.stop();
    System.out.println(stopWatch.toString());
}
 
Example 18
Source File: ProvRest.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Returns a JSON object with all the Activities sorted by date with latest first and all referenced Entities.
 * Parameters can be passed to control paging.
 *
 * @param uriInfo The URI information of the request to be used in creating links to other pages of Activities
 * @param offset The offset for the page.
 * @param limit The number of Activities to return in one page.
 * @return A JSON object with a key for activities and a key for entities
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("user")
@ApiOperation("Retrieves a JSON object with a paginated list of provenance Activities and referenced Entities")
public Response getActivities(@Context UriInfo uriInfo,
                       @DefaultValue("0") @QueryParam("offset") int offset,
                       @DefaultValue("50") @QueryParam("limit") int limit) {
    validateParams(limit, offset);
    List<Activity> activityList = new ArrayList<>();
    try (RepositoryConnection conn = provService.getConnection()) {
        StopWatch watch = new StopWatch();
        LOG.trace("Start collecting prov activities count");
        watch.start();
        TupleQuery countQuery = conn.prepareTupleQuery(GET_ACTIVITIES_COUNT_QUERY);
        TupleQueryResult countResult = countQuery.evaluateAndReturn();
        int totalCount;
        BindingSet bindingSet;
        if (!countResult.hasNext()
                || !(bindingSet = countResult.next()).getBindingNames().contains(ACTIVITY_COUNT_BINDING)
                || (totalCount = Bindings.requiredLiteral(bindingSet, ACTIVITY_COUNT_BINDING).intValue()) == 0) {
            watch.stop();
            LOG.trace("End collecting prov activities count: " + watch.getTime() + "ms");
            return Response.ok(createReturnObj(activityList)).header("X-Total-Count", 0).build();
        }
        watch.stop();
        LOG.trace("End collecting prov activities count: " + watch.getTime() + "ms");
        watch.reset();
        LOG.trace("Start collecting prov activities");
        watch.start();
        String queryStr = GET_ACTIVITIES_QUERY + "\nLIMIT " + limit + "\nOFFSET " + offset;
        TupleQuery query = conn.prepareTupleQuery(queryStr);
        TupleQueryResult result = query.evaluateAndReturn();
        result.forEach(bindings -> {
            Resource resource = vf.createIRI(Bindings.requiredResource(bindings, ACTIVITY_BINDING).stringValue());
            Activity fullActivity = provService.getActivity(resource).orElseThrow(() ->
                    ErrorUtils.sendError("Activity could not be found", Response.Status.INTERNAL_SERVER_ERROR));
            activityList.add(fullActivity);
        });
        watch.stop();
        LOG.trace("End collecting prov activities: " + watch.getTime() + "ms");
        watch.reset();
        Links links = LinksUtils.buildLinks(uriInfo, activityList.size(), totalCount, limit, offset);
        Response.ResponseBuilder response = Response.ok(createReturnObj(activityList))
                .header("X-Total-Count", totalCount);
        if (links.getNext() != null) {
            response = response.link(links.getBase() + links.getNext(), "next");
        }
        if (links.getPrev() != null) {
            response = response.link(links.getBase() + links.getPrev(), "prev");
        }
        return response.build();
    } catch (MobiException ex) {
        throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
 
Example 19
Source File: OntologyRest.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
private StreamingOutput getVocabularyStuffStream(Ontology ontology) {
    return outputStream -> {
        StopWatch watch = new StopWatch();
        log.trace("Start concepts");
        watch.start();

        outputStream.write("{\"concepts\": ".getBytes());
        outputStream.write(irisToJsonArray(getConceptIRIs(ontology)).toString().getBytes());

        watch.stop();
        log.trace("End concepts: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start conceptSchemes");
        watch.start();

        outputStream.write(", \"conceptSchemes\": ".getBytes());
        outputStream.write(irisToJsonArray(getConceptSchemeIRIs(ontology)).toString().getBytes());

        watch.stop();
        log.trace("End conceptSchemes: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start derivedConcepts");
        watch.start();

        outputStream.write(", \"derivedConcepts\": ".getBytes());
        outputStream.write(getDerivedConceptTypeIRIArray(ontology).toString().getBytes());

        watch.stop();
        log.trace("End derivedConcepts: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start derivedConceptSchemes");
        watch.start();

        outputStream.write(", \"derivedConceptSchemes\": ".getBytes());
        outputStream.write(getDerivedConceptSchemeTypeIRIArray(ontology).toString().getBytes());

        watch.stop();
        log.trace("End derivedConceptSchemes: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start derivedSemanticRelations");
        watch.start();

        outputStream.write(", \"derivedSemanticRelations\": ".getBytes());
        outputStream.write(getDerivedSemanticRelationIRIArray(ontology).toString().getBytes());

        watch.stop();
        log.trace("End derivedSemanticRelations: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start conceptHierarchy");
        watch.start();

        outputStream.write(", \"conceptHierarchy\": ".getBytes());
        writeHierarchyToStream(ontology.getConceptRelationships(valueFactory, modelFactory), outputStream);

        watch.stop();
        log.trace("End conceptHierarchy: " + watch.getTime() + "ms");
        watch.reset();
        log.trace("Start conceptSchemeHierarchy");
        watch.start();

        outputStream.write(", \"conceptSchemeHierarchy\": ".getBytes());
        writeHierarchyToStream(ontology.getConceptSchemeRelationships(valueFactory, modelFactory), outputStream);
        outputStream.write("}".getBytes());

        watch.stop();
        log.trace("End conceptSchemeHierarchy: " + watch.getTime() + "ms");
    };
}
 
Example 20
Source File: GraphManagerLoadTest.java    From usergrid with Apache License 2.0 2 votes vote down vote up
@Override
public Boolean call() throws Exception {
    GraphManager manager = factory.createEdgeManager( scope );


    final StopWatch timer = new StopWatch();
    timer.start();

    for ( int i = 0; i < writeLimit; i++ ) {

        Edge edge = generator.newEdge();

        Edge returned = manager.writeEdge( edge ).toBlocking().last();


        assertNotNull( "Returned has a version", returned.getTimestamp() );


        if ( i % 1000 == 0 ) {
            logger.info( "   Wrote: " + i );
        }
    }

    timer.stop();
    logger.info( "Total time to write {} entries {} ms", writeLimit, timer.getTime() );
    timer.reset();

    timer.start();

    final CountDownLatch latch = new CountDownLatch( 1 );


    generator.doSearch( manager ).take( readCount ).buffer( 1000 ).subscribe( new Subscriber<List<MarkedEdge>>() {
        @Override
        public void onCompleted() {
            timer.stop();
            latch.countDown();
        }


        @Override
        public void onError( final Throwable throwable ) {
            fail( "Exception occurced " + throwable );
        }


        @Override
        public void onNext( final List<MarkedEdge> edges ) {
            logger.info("Read {} edges", edges.size());
        }
    } );


    latch.await();


    logger.info( "Total time to read {} entries {} ms", readCount, timer.getTime() );

    return true;
}