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;
}
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);
}
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());
}
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());
}
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");
}
Aggregations