/** * @param theNumOperations Ok for this to be 0, it will be treated as 1 */ public int getMillisPerOperation(int theNumOperations) { return (int) (((double) getMillis()) / Math.max(1.0, theNumOperations)); }
/** * Determine the current throughput per unit of time (specified in theUnit) * assuming that theNumOperations operations have happened. * <p> * For example, if this stopwatch has 2 seconds elapsed, and this method is * called for theNumOperations=30 and TimeUnit=SECONDS, * this method will return 15 * </p> * * @see #formatThroughput(int, TimeUnit) */ public double getThroughput(int theNumOperations, TimeUnit theUnit) { if (theNumOperations <= 0) { return 0.0f; } long millisElapsed = Math.max(1, getMillis()); long periodMillis = theUnit.toMillis(1); double numerator = theNumOperations; double denominator = ((double) millisElapsed) / ((double) periodMillis); return numerator / denominator; }
@Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { int maxResult = 1000; Page<TermConcept> concepts = myConceptDao.findResourcesRequiringReindexing(new PageRequest(0, maxResult)); if (concepts.hasContent() == false) { if (myChildToParentPidCache != null) { ourLog.info("Clearing parent concept cache"); myNextReindexPass = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; myChildToParentPidCache = null; } return; } if (myChildToParentPidCache == null) { myChildToParentPidCache = ArrayListMultimap.create(); } ourLog.info("Indexing {} / {} concepts", concepts.getContent().size(), concepts.getTotalElements()); int count = 0; StopWatch stopwatch = new StopWatch(); for (TermConcept nextConcept : concepts) { if (isBlank(nextConcept.getParentPidsAsString())) { StringBuilder parentsBuilder = new StringBuilder(); createParentsString(parentsBuilder, nextConcept.getId()); nextConcept.setParentPids(parentsBuilder.toString()); } saveConcept(nextConcept); count++; } ourLog.info("Indexed {} / {} concepts in {}ms - Avg {}ms / resource", count, concepts.getContent().size(), stopwatch.getMillis(), stopwatch.getMillisPerOperation(count)); } });
/** * Formats value in an appropriate format. See {@link #formatMillis(long)}} * for a description of the format * * @see #formatMillis(long) */ @Override public String toString() { return formatMillis(getMillis()); }
/** * Given an amount of something completed so far, and a total amount, calculates how long it will take for something to complete * * @param theCompleteToDate The amount so far * @param theTotal The total (must be higher than theCompleteToDate * @return A formatted amount of time */ public String getEstimatedTimeRemaining(double theCompleteToDate, double theTotal) { double millis = getMillis(); long millisRemaining = (long) (((theTotal / theCompleteToDate) * millis) - (millis)); return formatMillis(millisRemaining); }
@Override public void rejectedExecution(Runnable theRunnable, ThreadPoolExecutor theExecutor) { ourLog.info("Note: Executor queue is full ({} elements), waiting for a slot to become available!", executorQueue.size()); StopWatch sw = new StopWatch(); try { executorQueue.put(theRunnable); } catch (InterruptedException theE) { throw new RejectedExecutionException("Task " + theRunnable.toString() + " rejected from " + theE.toString()); } ourLog.info("Slot become available after {}ms", sw.getMillis()); } };
@Override public void rejectedExecution(Runnable theRunnable, ThreadPoolExecutor theExecutor) { ourLog.info("Note: Subscription triggering queue is full ({} elements), waiting for a slot to become available!", executorQueue.size()); StopWatch sw = new StopWatch(); try { executorQueue.put(theRunnable); } catch (InterruptedException theE) { // Restore interrupted state... Thread.currentThread().interrupt(); throw new RejectedExecutionException("Task " + theRunnable.toString() + " rejected from " + theE.toString()); } ourLog.info("Slot become available after {}ms", sw.getMillis()); } };
private void ensureHaveQuery() { if (myWrap == null) { ourLog.debug("Searching for unique index matches over {} candidate query strings", myUniqueQueryStrings.size()); StopWatch sw = new StopWatch(); Collection<Long> resourcePids = myResourceIndexedCompositeStringUniqueDao.findResourcePidsByQueryStrings(myUniqueQueryStrings); ourLog.debug("Found {} unique index matches in {}ms", resourcePids.size(), sw.getMillis()); myWrap = resourcePids.iterator(); } }
@Transactional(propagation = Propagation.REQUIRED) @Override public Set<TermConcept> findCodesAbove(Long theCodeSystemResourcePid, Long theCodeSystemVersionPid, String theCode) { StopWatch stopwatch = new StopWatch(); TermConcept concept = fetchLoadedCode(theCodeSystemResourcePid, theCode); if (concept == null) { return Collections.emptySet(); } Set<TermConcept> retVal = new HashSet<>(); retVal.add(concept); fetchParents(concept, retVal); ourLog.info("Fetched {} codes above code {} in {}ms", retVal.size(), theCode, stopwatch.getMillis()); return retVal; }
protected void flushJpaSession() { SessionImpl session = (SessionImpl) myEntityManager.unwrap(Session.class); int insertionCount = session.getActionQueue().numberOfInsertions(); int updateCount = session.getActionQueue().numberOfUpdates(); StopWatch sw = new StopWatch(); myEntityManager.flush(); ourLog.debug("Session flush took {}ms for {} inserts and {} updates", sw.getMillis(), insertionCount, updateCount); }
protected void flushJpaSession() { SessionImpl session = (SessionImpl) myEntityManager.unwrap(Session.class); int insertionCount = session.getActionQueue().numberOfInsertions(); int updateCount = session.getActionQueue().numberOfUpdates(); StopWatch sw = new StopWatch(); myEntityManager.flush(); ourLog.debug("Session flush took {}ms for {} inserts and {} updates", sw.getMillis(), insertionCount, updateCount); }
public LinkedBlockingQueueSubscribableChannel(BlockingQueue<Runnable> theQueue, String theThreadNamingPattern) { ThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern(theThreadNamingPattern) .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = (theRunnable, theExecutor) -> { ourLog.info("Note: Executor queue is full ({} elements), waiting for a slot to become available!", theQueue.size()); StopWatch sw = new StopWatch(); try { theQueue.put(theRunnable); } catch (InterruptedException theE) { throw new RejectedExecutionException("Task " + theRunnable.toString() + " rejected from " + theE.toString()); } ourLog.info("Slot become available after {}ms", sw.getMillis()); }; ThreadPoolExecutor executor = new ThreadPoolExecutor( 1, SubscriptionConstants.EXECUTOR_THREAD_COUNT, 0L, TimeUnit.MILLISECONDS, theQueue, threadFactory, rejectedExecutionHandler); myQueue = theQueue; mySubscribableChannel = new ExecutorSubscribableChannel(executor); }
@Override public IBaseResource readByPid(Long thePid) { StopWatch w = new StopWatch(); Optional<ResourceTable> entity = myResourceTableDao.findById(thePid); if (!entity.isPresent()) { throw new ResourceNotFoundException("No resource found with PID " + thePid); } if (entity.get().getDeleted() != null) { throw new ResourceGoneException("Resource was deleted at " + new InstantType(entity.get().getDeleted()).getValueAsString()); } T retVal = toResource(myResourceType, entity.get(), null, false); ourLog.debug("Processed read on {} in {}ms", thePid, w.getMillis()); return retVal; }
ourLog.info("Refreshed search parameter cache in {}ms", sw.getMillis());
ourLog.info("Parsed {} candidateResources in {}ms", candidateResources.size(), sw.getMillis());
ourLog.info("Done sending email (took {}ms)", sw.getMillis());
ourLog.info("Subscription trigger job[{}] triggered {} resources in {}ms ({} res / second)", theJobDetails.getJobId(), totalSubmitted, sw.getMillis(), sw.getThroughput(totalSubmitted, TimeUnit.SECONDS));
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "successfulDeletes", 1, w.getMillis()); String severity = "information"; String code = "informational";