List of usage examples for org.apache.commons.lang.time StopWatch reset
public void reset()
Resets the stopwatch.
From source file:com.auditbucket.test.functional.TestForceDuplicateRlx.java
@Test public void uniqueChangeRLXUnderLoad() throws Exception { logger.info("uniqueChangeRLXUnderLoad started"); SecurityContextHolder.getContext().setAuthentication(authMike); regService.registerSystemUser(new RegistrationBean("TestTrack", mike, "bah").setIsUnique(false)); int auditMax = 10; int logMax = 10; int fortress = 1; String simpleJson = "{\"who\":"; ArrayList<Long> list = new ArrayList<>(); logger.info("FortressCount: " + fortressMax + " AuditCount: " + auditMax + " LogCount: " + logMax); logger.info(//from w ww . j a v a 2 s . co m "We will be expecting a total of " + (auditMax * logMax * fortressMax) + " messages to be handled"); StopWatch watch = new StopWatch(); watch.start(); double splitTotals = 0; long totalRows = 0; int auditSleepCount; // Discount all the time we spent sleeping DecimalFormat f = new DecimalFormat("##.000"); while (fortress <= fortressMax) { String fortressName = "bulkloada" + fortress; int audit = 1; long requests = 0; auditSleepCount = 0; Fortress iFortress = fortressService.registerFortress(new FortressInputBean(fortressName, true)); requests++; logger.info("Starting run for " + fortressName); while (audit <= auditMax) { MetaInputBean aib = new MetaInputBean(iFortress.getName(), fortress + "olivia@sunnybell.com", "CompanyNode", new DateTime(), "ABC" + audit); TrackResultBean arb = trackEP.trackHeader(aib, null, null).getBody(); requests++; int log = 1; while (log <= logMax) { createLog(simpleJson, aib, arb, log); requests++; log++; } // Logs created audit++; } // Audit headers finished with watch.split(); double fortressRunTime = (watch.getSplitTime() - auditSleepCount) / 1000d; logger.info("*** " + iFortress.getName() + " took " + fortressRunTime + " avg processing time for [" + requests + "] RPS= " + f.format(fortressRunTime / requests) + ". Requests per second " + f.format(requests / fortressRunTime)); splitTotals = splitTotals + fortressRunTime; totalRows = totalRows + requests; watch.reset(); watch.start(); list.add(iFortress.getId()); fortress++; } logger.info("*** Created data set in " + f.format(splitTotals) + " fortress avg = " + f.format(splitTotals / fortressMax) + " avg processing time per request " + f.format(splitTotals / totalRows) + ". Requests per second " + f.format(totalRows / splitTotals)); watch.reset(); }
From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.SampleListingWorker.java
/** * Load the samples defined by the criteria given to the constructor. The samples will be * enriched with sample properties and dependencies to parents and container will be resolved. *//*from www . j a va 2 s . co m*/ public List<Sample> load() { final StopWatch watch = new StopWatch(); watch.start(); final Experiment expOrNull = tryLoadExperiment(); final boolean oneGroupPerSample = isOneGroupPerSamples(); final Group groupOrNull; if (oneGroupPerSample) { groupOrNull = null; final Group[] groups = referencedEntityDAO.getAllGroups(databaseInstanceId); for (Group group : groups) { group.setInstance(databaseInstance); groupMap.put(group.getId(), group); } } else { groupOrNull = tryLoadGroup(expOrNull); if (groupOrNull != null) { // For use by dependent samples. groupMap.put(groupOrNull.getId(), groupOrNull); } } loadSampleTypes(); retrievePrimaryBasicSamples(tryGetIteratorForSamplesByIds(), groupOrNull, oneGroupPerSample); retrievePrimaryBasicSamples(tryGetIteratorForGroupSamples(), groupOrNull, oneGroupPerSample); retrievePrimaryBasicSamples(tryGetIteratorForSharedSamples(), groupOrNull, oneGroupPerSample); retrievePrimaryBasicSamples(tryGetIteratorForExperimentSamples(), groupOrNull, oneGroupPerSample); retrievePrimaryBasicSamples(tryGetIteratorForContainedSamples(), groupOrNull, oneGroupPerSample); if (operationLog.isDebugEnabled()) { watch.stop(); operationLog.debug( String.format("Basic retrieval of %d samples took %s s", sampleList.size(), watch.toString())); watch.reset(); watch.start(); } // Only enrich the "primary" samples (matching the criteria) with properties, not // dependent samples. if (samplePropertiesEnricherOrNull != null) { samplePropertiesEnricherOrNull.enrich(sampleMap.keySet(), new IEntityPropertiesHolderResolver() { public Sample get(long id) { return sampleMap.get(id); } }); if (operationLog.isDebugEnabled()) { watch.stop(); operationLog.debug(String.format("Enrichment with properties took %s s", watch.toString())); } } retrieveDependentSamplesRecursively(); resolveParents(); resolveContainers(); return sampleList; }
From source file:com.qualogy.qafe.mgwt.server.RPCServiceImpl.java
public UIVOCluster getUISFromApplicationContext(Map<String, String> parameters) throws GWTServiceException { if (getServletContext().getAttribute("init_failure") != null) { Throwable throwable = (Throwable) getServletContext().getAttribute("init_failure"); getServletContext().removeAttribute("init_failure"); getServletContext().removeAttribute("init_failure_message"); throw handleException(throwable); } else {/* w w w .j a v a 2 s . co m*/ try { UIVOCluster cluster = null; Iterator<ApplicationIdentifier> contextItr = ApplicationCluster.getInstance().keysIterator(); String appId = null; String windowSession = null; cluster = new UIVOCluster(); cluster.setExternalProperties(ApplicationClusterUtil.getExternalProperties()); cluster.setDebugMode(ContextLoaderHelper.isDebugMode()); cluster.setShowLog(ContextLoaderHelper.showLog()); cluster.setGlobalDateFormat(ApplicationClusterUtil.getGlobalDateFormat()); cluster.setReloadable(ContextLoaderHelper.isReloadable(getThreadLocalRequest())); cluster.setUseDockMode(ContextLoaderHelper.isDockMode()); cluster.setSystemMenuApplication( service.getSystemApplication(ApplicationCluster.getInstance().getSystemApplicationContext(), appId, windowSession, getLocale(), parameters)); List<UIGVO> gvoList = new ArrayList<UIGVO>(); StopWatch stopWatch = new StopWatch(); while (contextItr.hasNext()) { ApplicationIdentifier key = contextItr.next(); if (!ApplicationClusterUtil.isSystemApplication(key)) { stopWatch.start(); UIGVO uigvo = null; ApplicationContext context = ApplicationCluster.getInstance().get(key); if (context.getLoadException() == null) { try { uigvo = service.getUI(context.getId(), appId, windowSession, getLocale(), parameters); } catch (Exception e) { String errorMessage = e != null ? "(" + e.getMessage() + ")" : ""; String message = key.toString() + " caused exception : " + errorMessage; cluster.getMessages().add(message); } } if (uigvo != null) { uigvo.setAppId(context.getId().toString()); uigvo.setDebug(Boolean.valueOf(context.getConfigurationItem(/* * Configuration. * DEVELOPMENT_MODE */""))); uigvo.setTitle(context.getName()); stopWatch.stop(); uigvo.setTime(Long.valueOf(stopWatch.getTime())); logger.info("Application -" + context.getName() + " is rendered in " + stopWatch.getTime() + "ms"); stopWatch.reset(); gvoList.add(uigvo); } else { stopWatch.stop(); stopWatch.reset(); String errorMessage = context.getLoadException() != null ? "(" + context.getLoadException().getMessage() + ")" : ""; String message = "Application with id " + key.toString() + " is not loaded! " + errorMessage; cluster.getMessages().add(message); } if (context.getWarningMessages() != null) { for (String strMsg : context.getWarningMessages()) { cluster.getMessages().add(strMsg); } } } } cluster.setVos(gvoList.toArray(new UIGVO[] {})); cluster = service.stripCluster(cluster); String css = CssProvider.getInstance().generateTypedCSS("gwt", null); cluster.setCss(css); return cluster; } catch (Exception e) { throw handleException(e); } } }
From source file:com.qualogy.qafe.gwt.server.RPCServiceImpl.java
public UIVOCluster getUISFromApplicationContext(Map<String, String> parameters) throws GWTServiceException { if (getServletContext().getAttribute("init_failure") != null) { Throwable throwable = (Throwable) getServletContext().getAttribute("init_failure"); getServletContext().removeAttribute("init_failure"); getServletContext().removeAttribute("init_failure_message"); throw handleException(throwable); } else {/*from ww w . j a v a 2 s . c o m*/ try { Iterator<ApplicationIdentifier> contextItr = ApplicationCluster.getInstance().keysIterator(); String appId = null; String windowSession = null; UIVOCluster cluster = new UIVOCluster(); cluster.setExternalProperties(ApplicationClusterUtil.getExternalProperties()); cluster.setDebugMode(ContextLoaderHelper.isDebugMode()); cluster.setShowLog(ContextLoaderHelper.showLog()); cluster.setGlobalDateFormat(ApplicationClusterUtil.getGlobalDateFormat()); cluster.setReloadable(ContextLoaderHelper.isReloadable(getThreadLocalRequest())); cluster.setUseDockMode(ContextLoaderHelper.isDockMode()); cluster.setClientSideEventEnabled(ApplicationCluster.getInstance().isClientSideEventEnabled()); UIGVO uiGVO = service.getSystemApplication( ApplicationCluster.getInstance().getSystemApplicationContext(), appId, windowSession, getLocale(), parameters); cluster.setSystemMenuApplication(uiGVO); List<UIGVO> gvoList = new ArrayList<UIGVO>(); StopWatch stopWatch = new StopWatch(); while (contextItr.hasNext()) { ApplicationIdentifier key = contextItr.next(); if (!ApplicationClusterUtil.isSystemApplication(key)) { stopWatch.start(); UIGVO uigvo = null; ApplicationContext context = ApplicationCluster.getInstance().get(key); if (context.getLoadException() == null) { try { uigvo = service.getUI(context.getId(), appId, windowSession, getLocale(), parameters); } catch (Exception e) { String errorMessage = e != null ? "(" + e.getMessage() + ")" : ""; String message = key.toString() + " caused exception : <br>" + errorMessage; cluster.getMessages().add(message); } } if (uigvo != null) { uigvo.setAppId(context.getId().toString()); uigvo.setDebug(Boolean.valueOf(context.getConfigurationItem(/* * Configuration. * DEVELOPMENT_MODE */""))); uigvo.setTitle(context.getName()); stopWatch.stop(); uigvo.setTime(Long.valueOf(stopWatch.getTime())); logger.info("Application -" + context.getName() + " is rendered in " + stopWatch.getTime() + "ms"); stopWatch.reset(); gvoList.add(uigvo); } else { stopWatch.stop(); stopWatch.reset(); String errorMessage = context.getLoadException() != null ? context.getLoadException().getMessage() : ""; String message = "Application [" + key.toString() + "] is not loaded, because of the following:<br>" + errorMessage; cluster.getMessages().add(message); } if (context.getWarningMessages() != null) { for (String strMsg : context.getWarningMessages()) { cluster.getMessages().add(strMsg); } } } } cluster.setVos(gvoList.toArray(new UIGVO[] {})); cluster = service.stripCluster(cluster); return cluster; } catch (Exception e) { throw handleException(e); } } }
From source file:com.auditbucket.test.functional.TestAuditIntegration.java
@Test public void stressWithHighVolume() throws Exception { assumeTrue(!ignoreMe);//from w w w .j a v a2 s .c o m logger.info("stressWithHighVolume started"); SecurityContextHolder.getContext().setAuthentication(authA); //Neo4jHelper.cleanDb(graphDatabaseService, true); regService.registerSystemUser(new RegistrationBean("TestTrack", email, "bah")); int auditMax = 10; int logMax = 10; int fortress = 1; //fortressMax = 10; String simpleJson = "{\"who\":"; ArrayList<Long> list = new ArrayList<>(); logger.info("FortressCount: " + fortressMax + " AuditCount: " + auditMax + " LogCount: " + logMax); logger.info( "We will be expecting a total of " + (auditMax * logMax * fortressMax) + " messages to be handled"); StopWatch watch = new StopWatch(); watch.start(); double splitTotals = 0; long totalRows = 0; int auditSleepCount; // Discount all the time we spent sleeping DecimalFormat f = new DecimalFormat("##.000"); while (fortress <= fortressMax) { String fortressName = "bulkloada" + fortress; int audit = 1; long requests = 0; auditSleepCount = 0; Fortress iFortress = fortressService.registerFortress(new FortressInputBean(fortressName, false)); requests++; logger.info("Starting run for " + fortressName); while (audit <= auditMax) { boolean searchChecked = false; MetaInputBean aib = new MetaInputBean(iFortress.getName(), fortress + "olivia@sunnybell.com", "CompanyNode", new DateTime(), "ABC" + audit); TrackResultBean arb = mediationFacade.createHeader(aib, null); requests++; int log = 1; while (log <= logMax) { //String escJson = Helper.getBigJsonText(log); //trackService.createLog(new LogInputBean(arb.getMetaKey(), aib.getFortressUser(), new DateTime(), escJson )); createLog(simpleJson, aib, arb, log); //Thread.sleep(100); requests++; if (!searchChecked) { searchChecked = true; MetaHeader metaHeader = trackService.getHeader(arb.getMetaKey()); requests++; int checkCount = waitForHeaderToUpdate(metaHeader); auditSleepCount = auditSleepCount + (400 * checkCount); requests = requests + checkCount; } // searchCheck done log++; } // Logs created audit++; } // Audit headers finished with watch.split(); double fortressRunTime = (watch.getSplitTime() - auditSleepCount) / 1000d; logger.info("*** " + iFortress.getName() + " took " + fortressRunTime + " avg processing time for [" + requests + "] RPS= " + f.format(fortressRunTime / requests) + ". Requests per second " + f.format(requests / fortressRunTime)); splitTotals = splitTotals + fortressRunTime; totalRows = totalRows + requests; watch.reset(); watch.start(); list.add(iFortress.getId()); fortress++; } logger.info("*** Created data set in " + f.format(splitTotals) + " fortress avg = " + f.format(splitTotals / fortressMax) + " avg processing time per request " + f.format(splitTotals / totalRows) + ". Requests per second " + f.format(totalRows / splitTotals)); watch.reset(); Thread.sleep(5000); // give things a final chance to complete validateLogsIndexed(list, auditMax, logMax); doSearchTests(auditMax, list, watch); }
From source file:edu.internet2.middleware.psp.grouper.PspChangeLogConsumer.java
/** {@inheritDoc} */ public long processChangeLogEntries(final List<ChangeLogEntry> changeLogEntryList, ChangeLogProcessorMetadata changeLogProcessorMetadata) { // the change log sequence number to return long sequenceNumber = -1; // initialize this consumer's name from the change log metadata if (name == null) { name = changeLogProcessorMetadata.getConsumerName(); LOG.trace("PSP Consumer '{}' - Setting name.", name); }/* w ww . ja v a2 s . co m*/ // time context processing StopWatch stopWatch = new StopWatch(); // the last change log sequence number processed String lastContextId = null; LOG.debug("PSP Consumer '{}' - Processing change log entry list size '{}'", name, changeLogEntryList.size()); // process each change log entry for (ChangeLogEntry changeLogEntry : changeLogEntryList) { // return the current change log sequence number sequenceNumber = changeLogEntry.getSequenceNumber(); // if full sync is running, return the previous sequence number to process this entry on the next run if (fullSyncIsRunning) { LOG.info("PSP Consumer '{}' - Full sync is running, returning sequence number '{}'", name, sequenceNumber - 1); return sequenceNumber - 1; } // if first run, start the stop watch and store the last sequence number if (lastContextId == null) { stopWatch.start(); lastContextId = changeLogEntry.getContextId(); } // whether or not an exception was thrown during processing of the change log entry boolean errorOccurred = false; try { // process the change log entry processChangeLogEntry(changeLogEntry); } catch (Exception e) { errorOccurred = true; String message = "PSP Consumer '" + name + "' - An error occurred processing sequence number " + sequenceNumber; LOG.error(message, e); changeLogProcessorMetadata.registerProblem(e, message, sequenceNumber); changeLogProcessorMetadata.setHadProblem(true); changeLogProcessorMetadata.setRecordException(e); changeLogProcessorMetadata.setRecordExceptionSequence(sequenceNumber); } // if the change log context id has changed, log and restart stop watch if (!lastContextId.equals(changeLogEntry.getContextId())) { stopWatch.stop(); LOG.debug("PSP Consumer '{}' - Processed change log context '{}' Elapsed time {}", new Object[] { name, lastContextId, stopWatch, }); stopWatch.reset(); stopWatch.start(); } lastContextId = changeLogEntry.getContextId(); // if an error occurs and retry on error is true, return the current sequence number minus 1 if (errorOccurred && retryOnError) { sequenceNumber--; break; } } // stop the timer and log stopWatch.stop(); LOG.debug("PSP Consumer '{}' - Processed change log context '{}' Elapsed time {}", new Object[] { name, lastContextId, stopWatch, }); if (sequenceNumber == -1) { LOG.error("PSP Consumer '" + name + "' - Unable to process any records."); throw new RuntimeException("PSP Consumer '" + name + "' - Unable to process any records."); } LOG.debug("PSP Consumer '{}' - Finished processing change log entries. Last sequence number '{}'", name, sequenceNumber); // return the sequence number return sequenceNumber; }
From source file:edu.internet2.middleware.changelogconsumer.googleapps.GoogleAppsChangeLogConsumer.java
/** {@inheritDoc} */ @Override/*from w w w . j a va2 s.com*/ public long processChangeLogEntries(final List<ChangeLogEntry> changeLogEntryList, ChangeLogProcessorMetadata changeLogProcessorMetadata) { LOG.debug("Google Apps Consumer - waking up"); // the change log sequence number to return long sequenceNumber = -1; // initialize this consumer's consumerName from the change log metadata if (consumerName == null) { consumerName = changeLogProcessorMetadata.getConsumerName(); LOG.trace("Google Apps Consumer '{}' - Setting name.", consumerName); } GoogleAppsSyncProperties properties = new GoogleAppsSyncProperties(consumerName); try { connector.initialize(consumerName, properties); if (properties.getprefillGoogleCachesForConsumer()) { connector.populateGoogleCache(); } } catch (Exception e) { LOG.error("Google Apps Consumer '{}' - This consumer failed to initialize: {}", consumerName, e.getMessage()); return changeLogEntryList.get(0).getSequenceNumber() - 1; } GrouperSession grouperSession = null; try { grouperSession = GrouperSession.startRootSession(); syncAttribute = connector.getGoogleSyncAttribute(); connector.cacheSyncedGroupsAndStems(); // time context processing final StopWatch stopWatch = new StopWatch(); // the last change log sequence number processed String lastContextId = null; LOG.debug("Google Apps Consumer '{}' - Processing change log entry list size '{}'", consumerName, changeLogEntryList.size()); // process each change log entry for (ChangeLogEntry changeLogEntry : changeLogEntryList) { // return the current change log sequence number sequenceNumber = changeLogEntry.getSequenceNumber(); // if full sync is running, return the previous sequence number to process this entry on the next run boolean isFullSyncRunning = GoogleAppsFullSync.isFullSyncRunning(consumerName); if (isFullSyncRunning) { LOG.info("Google Apps Consumer '{}' - Full sync is running, returning sequence number '{}'", consumerName, sequenceNumber - 1); return sequenceNumber - 1; } // if first run, start the stop watch and store the last sequence number if (lastContextId == null) { stopWatch.start(); lastContextId = changeLogEntry.getContextId(); } // whether or not an exception was thrown during processing of the change log entry boolean errorOccurred = false; try { // process the change log entry processChangeLogEntry(changeLogEntry); } catch (Exception e) { errorOccurred = true; String message = "Google Apps Consumer '" + consumerName + "' - An error occurred processing sequence number " + sequenceNumber; LOG.error(message, e); changeLogProcessorMetadata.registerProblem(e, message, sequenceNumber); changeLogProcessorMetadata.setHadProblem(true); changeLogProcessorMetadata.setRecordException(e); changeLogProcessorMetadata.setRecordExceptionSequence(sequenceNumber); } // if the change log context id has changed, log and restart stop watch if (!lastContextId.equals(changeLogEntry.getContextId())) { stopWatch.stop(); LOG.debug("Google Apps Consumer '{}' - Processed change log context '{}' Elapsed time {}", new Object[] { consumerName, lastContextId, stopWatch, }); stopWatch.reset(); stopWatch.start(); } lastContextId = changeLogEntry.getContextId(); // if an error occurs and retry on error is true, return the current sequence number minus 1 /* Whether or not to retry a change log entry if an error occurs. */ boolean retryOnError = properties.isRetryOnError(); if (errorOccurred && retryOnError) { sequenceNumber--; break; } } // stop the timer and log stopWatch.stop(); LOG.debug("Google Apps Consumer '{}' - Processed change log context '{}' Elapsed time {}", new Object[] { consumerName, lastContextId, stopWatch, }); } finally { GrouperSession.stopQuietly(grouperSession); } if (sequenceNumber == -1) { LOG.error("Google Apps Consumer '" + consumerName + "' - Unable to process any records."); throw new RuntimeException( "Google Apps Consumer '" + consumerName + "' - Unable to process any records."); } LOG.debug("Google Apps Consumer '{}' - Finished processing change log entries. Last sequence number '{}'", consumerName, sequenceNumber); // return the sequence number return sequenceNumber; }
From source file:nu.mine.kino.projects.ACCreatorTest.java
@Test public void test() throws FileNotFoundException, ProjectException { File input = new File("project_management_tools.xls"); File input_base = new File("base_project_management_tools.xls"); System.out.println(input.getAbsolutePath()); StopWatch watch = new StopWatch(); watch.start();//from w w w .j ava2s . c o m List<ACBean> createACList = ACCreator.createACList(input, input_base); watch.stop(); for (ACBean acBean : createACList) { System.out.println(acBean); } System.out.println(watch.getTime() + " ms."); watch.reset(); }
From source file:nu.mine.kino.projects.ACCreatorTest.java
@Test public void test2() throws FileNotFoundException, ProjectException { File input = new File("project_management_tools.xls"); File input_base = new File("base_project_management_tools.xls"); System.out.println(input.getAbsolutePath()); StopWatch watch = new StopWatch(); watch.start();/*from w w w .j av a 2 s . c om*/ List<ACBean> createACList = ACCreator.createACList(input, input_base); List<ACBean> filterAC = ProjectUtils.filterList(createACList); watch.stop(); printList(createACList); printList(filterAC); System.out.println(watch.getTime() + " ms."); watch.reset(); }
From source file:nu.mine.kino.projects.ACCreatorTest.java
@Test public void test3() throws FileNotFoundException, ProjectException { ProjectWriter.write(new File("project_management_tools.xls")); ProjectWriter.write(new File("base_project_management_tools.xls")); File input = new File("project_management_tools.xls.json"); File input_base = new File("base_project_management_tools.xls.json"); System.out.println(input.getAbsolutePath()); StopWatch watch = new StopWatch(); watch.start();/*from w ww . java 2 s.c o m*/ List<ACBean> createACList = ACCreator.createACListFromJSON(input, input_base); List<ACBean> filterAC = ProjectUtils.filterList(createACList); watch.stop(); printList(createACList); printList(filterAC); System.out.println(watch.getTime() + " ms."); watch.reset(); }