Search in sources :

Example 21 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project motech by motech.

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class LinkerTermMatcher method handleBatch.

private void handleBatch(final GraphDatabaseService graphDb, TermMatcher termMatcher, final Map<Long, TaxonNode> nodeMap, int counter) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    String msgPrefix = "batch #" + counter / BATCH_SIZE;
    LOG.info(msgPrefix + " preparing...");
    List<String> nodeIdAndNames = new ArrayList<String>();
    for (Map.Entry<Long, TaxonNode> entry : nodeMap.entrySet()) {
        String name = entry.getKey() + "|" + entry.getValue().getName();
        nodeIdAndNames.add(name);
    }
    try {
        if (nodeIdAndNames.size() > 0) {
            termMatcher.findTermsForNames(nodeIdAndNames, new TermMatchListener() {

                @Override
                public void foundTaxonForName(Long nodeId, String name, Taxon taxon, NameType relType) {
                    TaxonNode taxonNode = nodeMap.get(nodeId);
                    if (taxonNode != null && NameType.NONE != relType && !TaxonUtil.likelyHomonym(taxon, taxonNode)) {
                        NodeUtil.connectTaxa(taxon, taxonNode, graphDb, RelTypes.forType(relType));
                    }
                }
            });
        }
    } catch (PropertyEnricherException ex) {
        LOG.error(msgPrefix + " problem matching terms", ex);
    }
    stopWatch.stop();
    LOG.info(msgPrefix + " completed in [" + stopWatch.getTime() + "] ms (" + (1.0 * stopWatch.getTime() / BATCH_SIZE) + " ms/name )");
    nodeMap.clear();
}
Also used : PropertyEnricherException(org.eol.globi.service.PropertyEnricherException) TaxonNode(org.eol.globi.domain.TaxonNode) Taxon(org.eol.globi.domain.Taxon) ArrayList(java.util.ArrayList) NameType(org.eol.globi.domain.NameType) StopWatch(org.apache.commons.lang.time.StopWatch) HashMap(java.util.HashMap) Map(java.util.Map) TermMatchListener(org.eol.globi.taxon.TermMatchListener)

Example 23 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class GeoNamesServiceImplTest method retrievePointForSpireLocalityAndCache.

@Test
public void retrievePointForSpireLocalityAndCache() throws IOException {
    GeoNamesService geoNamesServiceImpl = new GeoNamesServiceImpl();
    StopWatch watch = new StopWatch();
    watch.start();
    assertVenezuela(geoNamesServiceImpl);
    watch.stop();
    long firstDurationMs = watch.getTime();
    watch.reset();
    watch.start();
    assertVenezuela(geoNamesServiceImpl);
    watch.stop();
    long secondDurationMs = watch.getTime();
    assertThat("first request should be much slower than second due to caching", firstDurationMs, is(greaterThan(10 * secondDurationMs)));
}
Also used : StopWatch(org.apache.commons.lang.time.StopWatch) Test(org.junit.Test)

Example 24 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class GeoNamesServiceImplTest method retrievePointForGEONAMEIdAndCache.

@Test
public void retrievePointForGEONAMEIdAndCache() throws IOException {
    GeoNamesService geoNamesServiceImpl = new GeoNamesServiceImpl();
    StopWatch watch = new StopWatch();
    watch.start();
    LatLng point = lookupByGeoNameTerm(geoNamesServiceImpl);
    assertThat(point, is(notNullValue()));
    watch.stop();
    long firstDurationMs = watch.getTime();
    watch.reset();
    watch.start();
    lookupByGeoNameTerm(geoNamesServiceImpl);
    watch.stop();
    long secondDurationMs = watch.getTime();
    assertThat("first request should be much slower than second due to caching", firstDurationMs, is(greaterThan(10 * secondDurationMs)));
}
Also used : LatLng(org.eol.globi.geo.LatLng) StopWatch(org.apache.commons.lang.time.StopWatch) Test(org.junit.Test)

Example 25 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project eol-globi-data by jhpoelen.

the class HttpUtilIT method assertCaching.

protected void assertCaching(String nonCacheableUri) throws IOException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    HttpClient httpClient = HttpUtil.getHttpClient();
    httpClient.execute(new HttpGet(nonCacheableUri), new BasicResponseHandler());
    stopWatch.stop();
    long firstDelay = stopWatch.getTime();
    stopWatch.reset();
    stopWatch.start();
    HttpUtil.getHttpClient().execute(new HttpGet(nonCacheableUri), new BasicResponseHandler());
    long secondDelay = stopWatch.getTime();
    stopWatch.stop();
    assertThat("expected second delay [" + secondDelay + "] ms to be at least 10x shorter than first [" + firstDelay + "] ms", secondDelay, is(lessThan(firstDelay / 10)));
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

StopWatch (org.apache.commons.lang.time.StopWatch)48 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 File (java.io.File)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 ObjectOutputStream (java.io.ObjectOutputStream)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Map (java.util.Map)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 YarnApplicationReport (com.continuuity.weave.internal.yarn.YarnApplicationReport)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashSet (java.util.HashSet)2