Search in sources :

Example 86 with StopWatch

use of org.springframework.util.StopWatch in project cu-kfs by CU-CommunityApps.

the class AccountReversionImportStep method execute.

/**
 * @see org.kuali.kfs.sys.batch.AbstractWrappedBatchStep#getCustomBatchExecutor()
 */
public boolean execute(String str, Date date) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("AccountReversionImportStep");
    File f = new File(this.batchFileDirectoryName + System.getProperty("file.separator") + "AccountReversion.csv");
    AccountReversionImportService aris = SpringContext.getBean(AccountReversionImportService.class);
    aris.importAccountReversions(f);
    addTimeStampToFileName(f, "AccountReversion.csv", this.batchFileDirectoryName);
    stopWatch.stop();
    LOG.info("AccountReversionImportStep took " + (stopWatch.getTotalTimeSeconds() / 60.0) + " minutes to complete");
    return true;
}
Also used : AccountReversionImportService(edu.cornell.kfs.coa.service.AccountReversionImportService) File(java.io.File) StopWatch(org.springframework.util.StopWatch)

Example 87 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class SimpleMessageGroupTests method testPerformance_INT3846.

@Test
public // This test used to take 2 min and half to run; now ~200 milliseconds.
void testPerformance_INT3846() {
    Collection<Message<?>> messages = new ArrayList<>();
    for (int i = 0; i < 100000; i++) {
        messages.add(new GenericMessage<Object>("foo"));
    }
    SimpleMessageGroup group = new SimpleMessageGroup(messages, this.key);
    StopWatch watch = new StopWatch();
    watch.start();
    for (Message<?> message : messages) {
        group.getMessages().contains(message);
    }
    watch.stop();
    assertTrue(watch.getTotalTimeMillis() < 5000);
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 88 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class AggregatorTests method testAggPerf.

@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);
    });
    SimpleMessageStore store = new SimpleMessageStore();
    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(SimpleMessageGroupFactory.GroupType.LIST);
    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());
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageGroupFactory(org.springframework.integration.store.SimpleMessageGroupFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) StopWatch(org.springframework.util.StopWatch) GenericMessage(org.springframework.messaging.support.GenericMessage) CompletableFuture(java.util.concurrent.CompletableFuture) Collection(java.util.Collection) Test(org.junit.Test)

Example 89 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class AggregatorTests method testCustomAggPerf.

@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;
        }

        @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());
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) ArrayList(java.util.ArrayList) StopWatch(org.springframework.util.StopWatch) GenericMessage(org.springframework.messaging.support.GenericMessage) CompletableFuture(java.util.concurrent.CompletableFuture) MessageChannel(org.springframework.messaging.MessageChannel) Collection(java.util.Collection) AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) Test(org.junit.Test)

Example 90 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class MessageIdGenerationTests method performanceTest.

@Test
@Ignore
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");
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Field(java.lang.reflect.Field) StopWatch(org.springframework.util.StopWatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

StopWatch (org.springframework.util.StopWatch)112 Test (org.junit.Test)44 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 List (java.util.List)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 Ignore (org.junit.Ignore)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4