List of usage examples for org.springframework.util StopWatch getTotalTimeSeconds
public double getTotalTimeSeconds()
From source file:org.springframework.boot.StartupInfoLogger.java
private StringBuilder getStartedMessage(StopWatch stopWatch) { StringBuilder message = new StringBuilder(); message.append("Started "); message.append(getApplicationName()); message.append(" in "); message.append(stopWatch.getTotalTimeSeconds()); try {/*from w w w . j ava 2s .c o m*/ double uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0; message.append(" seconds (JVM running for " + uptime + ")"); } catch (Throwable ex) { // No JVM time available } return message; }
From source file:org.springframework.integration.aggregator.AggregatorTests.java
@Test public void testAggPerf() throws InterruptedException, ExecutionException, TimeoutException { AggregatingMessageHandler handler = new AggregatingMessageHandler( new DefaultAggregatingMessageGroupProcessor()); handler.setCorrelationStrategy(message -> "foo"); handler.setReleaseStrategy(new MessageCountReleaseStrategy(60000)); handler.setExpireGroupsUponCompletion(true); handler.setSendPartialResultOnExpiry(true); DirectChannel outputChannel = new DirectChannel(); handler.setOutputChannel(outputChannel); final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>(); outputChannel.subscribe(message -> { Collection<?> payload = (Collection<?>) message.getPayload(); logger.warn("Received " + payload.size()); resultFuture.complete(payload);/*from ww w. j av a 2s. com*/ }); SimpleMessageStore store = new SimpleMessageStore(); SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory( SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE); store.setMessageGroupFactory(messageGroupFactory); handler.setMessageStore(store); Message<?> message = new GenericMessage<String>("foo"); StopWatch stopwatch = new StopWatch(); stopwatch.start(); for (int i = 0; i < 120000; i++) { if (i % 10000 == 0) { stopwatch.stop(); logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); stopwatch.start(); } handler.handleMessage(message); } stopwatch.stop(); logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS); assertNotNull(result); assertEquals(60000, result.size()); }
From source file:org.springframework.integration.aggregator.AggregatorTests.java
@Test public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException, TimeoutException { AggregatingMessageHandler handler = new AggregatingMessageHandler( new DefaultAggregatingMessageGroupProcessor()); handler.setCorrelationStrategy(message -> "foo"); handler.setReleasePartialSequences(true); DirectChannel outputChannel = new DirectChannel(); handler.setOutputChannel(outputChannel); final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>(); outputChannel.subscribe(message -> { Collection<?> payload = (Collection<?>) message.getPayload(); logger.warn("Received " + payload.size()); resultFuture.complete(payload);/* w w w .j a v a 2s.co m*/ }); SimpleMessageStore store = new SimpleMessageStore(); SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory( SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE); store.setMessageGroupFactory(messageGroupFactory); handler.setMessageStore(store); StopWatch stopwatch = new StopWatch(); stopwatch.start(); for (int i = 0; i < 120000; i++) { if (i % 10000 == 0) { stopwatch.stop(); logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); stopwatch.start(); } handler.handleMessage( MessageBuilder.withPayload("foo").setSequenceSize(120000).setSequenceNumber(i + 1).build()); } stopwatch.stop(); logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS); assertNotNull(result); assertEquals(120000, result.size()); assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0)); // actually < 2.0, was many minutes }
From source file:org.springframework.integration.aggregator.AggregatorTests.java
@Test public void testCustomAggPerf() throws InterruptedException, ExecutionException, TimeoutException { class CustomHandler extends AbstractMessageHandler { // custom aggregator, only handles a single correlation private final ReentrantLock lock = new ReentrantLock(); private final Collection<Message<?>> messages = new ArrayList<Message<?>>(60000); private final MessageChannel outputChannel; private CustomHandler(MessageChannel outputChannel) { this.outputChannel = outputChannel; }/*from w w w . j a v a 2 s .c o m*/ @Override public void handleMessageInternal(Message<?> requestMessage) { lock.lock(); try { this.messages.add(requestMessage); if (this.messages.size() == 60000) { List<Object> payloads = new ArrayList<Object>(this.messages.size()); for (Message<?> message : this.messages) { payloads.add(message.getPayload()); } this.messages.clear(); outputChannel.send(getMessageBuilderFactory().withPayload(payloads) .copyHeaders(requestMessage.getHeaders()).build()); } } finally { lock.unlock(); } } } DirectChannel outputChannel = new DirectChannel(); CustomHandler handler = new CustomHandler(outputChannel); final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>(); outputChannel.subscribe(message -> { Collection<?> payload = (Collection<?>) message.getPayload(); logger.warn("Received " + payload.size()); resultFuture.complete(payload); }); Message<?> message = new GenericMessage<String>("foo"); StopWatch stopwatch = new StopWatch(); stopwatch.start(); for (int i = 0; i < 120000; i++) { if (i % 10000 == 0) { stopwatch.stop(); logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); stopwatch.start(); } handler.handleMessage(message); } stopwatch.stop(); logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)"); Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS); assertNotNull(result); assertEquals(60000, result.size()); }
From source file:org.springframework.integration.core.MessageIdGenerationTests.java
@Test @Ignore//from w w w. ja va 2 s . c om public void performanceTest() { int times = 1000000; StopWatch watch = new StopWatch(); watch.start(); for (int i = 0; i < times; i++) { new GenericMessage<Integer>(0); } watch.stop(); double defaultGeneratorElapsedTime = watch.getTotalTimeSeconds(); Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator"); ReflectionUtils.makeAccessible(idGeneratorField); ReflectionUtils.setField(idGeneratorField, null, (IdGenerator) () -> TimeBasedUUIDGenerator.generateId()); watch = new StopWatch(); watch.start(); for (int i = 0; i < times; i++) { new GenericMessage<Integer>(0); } watch.stop(); double timebasedGeneratorElapsedTime = watch.getTotalTimeSeconds(); logger.info("Generated " + times + " messages using default UUID generator " + "in " + defaultGeneratorElapsedTime + " seconds"); logger.info("Generated " + times + " messages using Timebased UUID generator " + "in " + timebasedGeneratorElapsedTime + " seconds"); logger.info("Time-based ID generator is " + defaultGeneratorElapsedTime / timebasedGeneratorElapsedTime + " times faster"); }
From source file:org.springframework.integration.history.MessageHistoryIntegrationTests.java
@Test @Ignore/*www. ja v a2s .com*/ public void testMessageHistoryWithHistoryPerformance() { ConfigurableApplicationContext acWithHistory = new ClassPathXmlApplicationContext( "perfWithMessageHistory.xml", MessageHistoryIntegrationTests.class); ConfigurableApplicationContext acWithoutHistory = new ClassPathXmlApplicationContext( "perfWithoutMessageHistory.xml", MessageHistoryIntegrationTests.class); SampleGateway gatewayHistory = acWithHistory.getBean("sampleGateway", SampleGateway.class); DirectChannel endOfThePipeChannelHistory = acWithHistory.getBean("endOfThePipeChannel", DirectChannel.class); endOfThePipeChannelHistory.subscribe(message -> { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(message); }); SampleGateway gateway = acWithoutHistory.getBean("sampleGateway", SampleGateway.class); DirectChannel endOfThePipeChannel = acWithoutHistory.getBean("endOfThePipeChannel", DirectChannel.class); endOfThePipeChannel.subscribe(message -> { MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(message); }); StopWatch stopWatch = new StopWatch(); stopWatch.start(); for (int i = 0; i < 10000; i++) { gatewayHistory.echo("hello"); } stopWatch.stop(); logger.info("Elapsed time with history 10000 calls: " + stopWatch.getTotalTimeSeconds()); stopWatch = new StopWatch(); stopWatch.start(); for (int i = 0; i < 10000; i++) { gateway.echo("hello"); } stopWatch.stop(); logger.info("Elapsed time without history 10000 calls: " + stopWatch.getTotalTimeSeconds()); acWithHistory.close(); acWithoutHistory.close(); }
From source file:org.springframework.integration.monitor.DirectChannelMonitor.java
private Object monitorSend(MethodInvocation invocation, MessageChannel channel, Message<?> message) throws Throwable { if (logger.isTraceEnabled()) { logger.trace("Recording send on channel(" + channel + ") : message(" + message + ")"); }/* w w w.j av a 2s .c o m*/ final StopWatch timer = new StopWatch(channel + ".send:execution"); try { timer.start(); sendCount.incrementAndGet(); sendRate.increment(); Object result = invocation.proceed(); timer.stop(); if ((Boolean) result) { sendSuccessRatio.success(); sendDuration.append(timer.getTotalTimeSeconds()); } else { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); } return result; } catch (Throwable e) { sendSuccessRatio.failure(); sendErrorCount.incrementAndGet(); sendErrorRate.increment(); throw e; } finally { if (logger.isTraceEnabled()) { logger.trace(timer); } } }
From source file:org.springframework.integration.monitor.SimpleMessageHandlerMonitor.java
public void handleMessage(Message<?> message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException { if (logger.isTraceEnabled()) { logger.trace("messageHandler(" + handler + ") message(" + message + ") :"); }//from ww w. j av a 2s. co m String name = this.name; if (name == null) { name = handler.toString(); } StopWatch timer = new StopWatch(name + ".handle:execution"); try { timer.start(); handleCount.incrementAndGet(); handler.handleMessage(message); timer.stop(); duration.append(timer.getTotalTimeSeconds()); } catch (RuntimeException e) { errorCount.incrementAndGet(); throw e; } catch (Error e) { errorCount.incrementAndGet(); throw e; } }
From source file:uk.ac.ebi.atlas.experimentimport.analyticsindex.baseline.BaselineAnalyticsIndexerService.java
public int index(BaselineExperiment experiment) { String experimentAccession = experiment.getAccession(); ExperimentType experimentType = experiment.getType(); String defaultQueryFactorType = experiment.getExperimentalFactors().getDefaultQueryFactorType(); ExperimentDesign experimentDesign = experiment.getExperimentDesign(); ImmutableMap<String, String> ensemblSpeciesGroupedByAssayGroupId = SpeciesGrouper .buildEnsemblSpeciesGroupedByAssayGroupId(experiment); ImmutableSetMultimap<String, String> ontologyTermIdsByAssayAccession = expandOntologyTerms( experimentDesign.getAllOntologyTermIdsByAssayAccession()); ImmutableSetMultimap<String, String> conditionSearchTermsByAssayGroupId = buildConditionSearchTermsByAssayGroupId( experiment, ontologyTermIdsByAssayAccession); checkArgument(StringUtils.isNotBlank(defaultQueryFactorType)); LOGGER.info("Start indexing " + experimentAccession); StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); stopWatch.start();//from w w w. j a v a 2s . co m //TODO: move this to another class ObjectInputStream<BaselineAnalytics> inputStream = (experimentType == ExperimentType.PROTEOMICS_BASELINE) ? proteomicsBaselineAnalyticsInputStreamFactory.create(experimentAccession) : baselineAnalyticsInputStreamFactory.create(experimentAccession); int count = indexRnaSeqBaselineExperimentAnalytics(experimentAccession, experimentType, defaultQueryFactorType, conditionSearchTermsByAssayGroupId, ensemblSpeciesGroupedByAssayGroupId, inputStream); stopWatch.stop(); LOGGER.info(String.format("Done indexing %s, indexed %,d documents in %s seconds", experimentAccession, count, stopWatch.getTotalTimeSeconds())); return count; }
From source file:uk.ac.ebi.atlas.search.baseline.BaselineExperimentAssayGroupSearchService.java
public SortedSet<BaselineExperimentAssayGroup> query(Set<String> geneIds, Optional<String> condition, Optional<String> species) { LOGGER.info(String.format("<query> geneIds=%s, condition=%s", Joiner.on(", ").join(geneIds), condition)); StopWatch stopWatch = new StopWatch(getClass().getSimpleName()); stopWatch.start();/*from w ww . j a va 2s . c o m*/ String conditionString = condition.isPresent() ? condition.get() : ""; String speciesString = species.isPresent() ? species.get() : ""; Optional<ImmutableSet<IndexedAssayGroup>> indexedAssayGroups = fetchAssayGroupsForCondition( conditionString); SetMultimap<String, String> assayGroupsWithExpressionByExperiment = baselineExperimentAssayGroupsDao .fetchExperimentAssayGroupsWithNonSpecificExpression(indexedAssayGroups, Optional.of(geneIds)); SortedSet<BaselineExperimentAssayGroup> baselineExperimentAssayGroups = searchedForConditionButGotNoResults( conditionString, indexedAssayGroups) ? emptySortedSet() : buildResults(assayGroupsWithExpressionByExperiment, !StringUtils.isBlank(conditionString), speciesString); stopWatch.stop(); LOGGER.info(String.format("<query> %s results, took %s seconds", baselineExperimentAssayGroups.size(), stopWatch.getTotalTimeSeconds())); return baselineExperimentAssayGroups; }