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;
}
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();
}
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)));
}
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)));
}
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)));
}
Aggregations