use of org.javasimon.Split in project midpoint by Evolveum.
the class AbstractSchemaPerformanceTest method measureSingle.
protected double measureSingle(String label, CheckedProducer<?> producer, long executionTime, Stopwatch watch) throws CommonException {
long until = System.currentTimeMillis() + executionTime;
int iteration = 0;
while (System.currentTimeMillis() < until) {
Object result = null;
iteration++;
try (Split split = watch.start()) {
result = producer.get();
}
if (result == null) {
// just to make sure the result is used somehow (and not optimized away)
throw new IllegalStateException("null result from the producer");
}
}
double micros = ((double) executionTime) * 1000 / iteration;
String message = label + ": " + iteration + " iterations in " + executionTime + " milliseconds (" + micros + " us per iteration)";
System.out.println(message);
logger.info(message);
return micros;
}
use of org.javasimon.Split in project webofneeds by researchstudio-sat.
the class CreateNeedMessageProcessor method authorizeOwnerApplicationForNeed.
private void authorizeOwnerApplicationForNeed(final String ownerApplicationID, Need need) {
String stopwatchName = getClass().getName() + ".authorizeOwnerApplicationForNeed";
Stopwatch stopwatch = SimonManager.getStopwatch(stopwatchName + "_phase1");
Split split = stopwatch.start();
List<OwnerApplication> ownerApplications = ownerApplicationRepository.findByOwnerApplicationId(ownerApplicationID);
split.stop();
stopwatch = SimonManager.getStopwatch(stopwatchName + "_phase2");
split = stopwatch.start();
if (ownerApplications.size() > 0) {
logger.debug("owner application is already known");
OwnerApplication ownerApplication = ownerApplications.get(0);
List<OwnerApplication> authorizedApplications = need.getAuthorizedApplications();
if (authorizedApplications == null) {
authorizedApplications = new ArrayList<OwnerApplication>(1);
}
authorizedApplications.add(ownerApplication);
need.setAuthorizedApplications(authorizedApplications);
} else {
logger.debug("owner application is new - creating");
List<OwnerApplication> ownerApplicationList = new ArrayList<>(1);
OwnerApplication ownerApplication = new OwnerApplication();
ownerApplication.setOwnerApplicationId(ownerApplicationID);
ownerApplicationList.add(ownerApplication);
need.setAuthorizedApplications(ownerApplicationList);
logger.debug("setting OwnerApp ID: " + ownerApplicationList.get(0));
}
split.stop();
stopwatch = SimonManager.getStopwatch(stopwatchName + "_phase3");
split = stopwatch.start();
need = needRepository.save(need);
split.stop();
}
use of org.javasimon.Split in project webofneeds by researchstudio-sat.
the class MatchingLoadTestMonitorAction method doRun.
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
Stopwatch stopwatch = SimonManager.getStopwatch("atomHintFullRoundtrip");
if (event instanceof AtomCreatedEvent) {
Split split = stopwatch.start();
atomSplits.put(((AtomCreatedEvent) event).getAtomURI().toString(), split);
logger.info("RECEIVED EVENT {} for uri {}", event, ((AtomCreatedEvent) event).getAtomURI().toString());
long startTime = System.currentTimeMillis();
String atomUri = ((AtomCreatedEvent) event).getAtomURI().toString();
atomEventStartTime.put(atomUri, startTime);
} else if (event instanceof AtomHintFromMatcherEvent) {
String atomUri = ((AtomHintFromMatcherEvent) event).getRecipientAtom().toString();
logger.info("RECEIVED EVENT {} for uri {}", event, atomUri);
long hintReceivedTime = System.currentTimeMillis();
atomSplits.get(atomUri).stop();
hintEventReceivedTime.computeIfAbsent(atomUri, k -> new LinkedList<>());
hintEventReceivedTime.get(atomUri).add(hintReceivedTime);
} else if (event instanceof SocketHintFromMatcherEvent) {
String atomUri = ((SocketHintFromMatcherEvent) event).getRecipientSocket().toString();
logger.info("RECEIVED EVENT {} for uri {}", event, atomUri);
long hintReceivedTime = System.currentTimeMillis();
atomSplits.get(atomUri).stop();
hintEventReceivedTime.computeIfAbsent(atomUri, k -> new LinkedList<>());
hintEventReceivedTime.get(atomUri).add(hintReceivedTime);
}
if (startTestTime == -1) {
startTestTime = System.currentTimeMillis();
}
logger.info("Number of Atoms: {}", atomEventStartTime.size());
logger.info("Number of Hints: {}", getTotalHints());
logger.info("Number of Atoms with Hints: {}", getAtomsWithHints());
logger.info("Average Duration: {}", getAverageHintDuration());
logger.info("Minimum Duration: {}", getMinHintDuration());
logger.info("Maximum Duration: {}", getMaxHintDuration());
logger.info("Atoms with Hints per Second: {}", getAtomsWithAtomsPerSecond(startTestTime));
logger.info("Hints per Second: {}", getHintsPerSecondThroughput(startTestTime));
}
use of org.javasimon.Split in project webofneeds by researchstudio-sat.
the class MonitoringService method stopClock.
public void stopClock(String stopWatchName, String splitName) {
if (isMonitoringEnabled()) {
Map<String, Split> splits = stopWatchSplits.get(stopWatchName);
if (splits == null) {
logger.warn("No stopwatch '{}' found for monitoring end event", stopWatchName);
return;
}
Split split = splits.get(splitName);
if (split == null) {
logger.warn("No split '{}' in stopwatch '{}' found for monitoring end event", splitName, stopWatchName);
return;
}
split.stop();
// splits.remove(monitoringEvent.getSplitName());
}
}
use of org.javasimon.Split in project webofneeds by researchstudio-sat.
the class BaseEventBotAction method getActionTask.
@Override
public Runnable getActionTask(final Event event, final EventListener eventListener) {
return () -> {
MDC.clear();
Stopwatch stopwatch = SimonManager.getStopwatch(stopwatchName);
Split split = stopwatch.start();
try {
doRun(event, eventListener);
split.stop();
} catch (Exception e) {
eventListenerContext.getEventBus().publish(new ErrorEvent(e));
logger.warn("Encountered an Exception:", e);
split.stop(EXCEPTION_TAG);
} catch (Throwable t) {
logger.warn("could not run action {}", stopwatchName, t);
split.stop(EXCEPTION_TAG);
throw t;
}
};
}
Aggregations