use of org.springframework.util.StopWatch in project spring-integration by spring-projects.
the class MethodInvokingMessageProcessorTests method testPerformanceSpelVersusInvocable.
@Test
public void testPerformanceSpelVersusInvocable() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("integerMethod", Integer.class);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
processor.setUseSpelInvoker(true);
Message<Integer> message = MessageBuilder.withPayload(42).build();
StopWatch stopWatch = new StopWatch("SpEL vs Invocable Performance");
int count = 20_000;
stopWatch.start("SpEL");
for (int i = 0; i < count; i++) {
processor.processMessage(message);
}
stopWatch.stop();
processor = new MethodInvokingMessageProcessor(service, method);
stopWatch.start("Invocable");
for (int i = 0; i < count; i++) {
processor.processMessage(message);
}
stopWatch.stop();
DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor);
processor = new MethodInvokingMessageProcessor(service, method);
processor.setUseSpelInvoker(true);
stopWatch.start("Compiled SpEL");
for (int i = 0; i < count; i++) {
processor.processMessage(message);
}
stopWatch.stop();
logger.warn(stopWatch.prettyPrint());
compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF);
}
use of org.springframework.util.StopWatch in project spring-integration by spring-projects.
the class AcceptOnceFileListFilterTests method testPerformance_INT3572.
@Test
public // This test used to take 34 seconds to run; now 25 milliseconds.
void testPerformance_INT3572() {
StopWatch watch = new StopWatch();
watch.start();
AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>();
for (int i = 0; i < 100000; i++) {
filter.accept("" + i);
}
watch.stop();
assertTrue(watch.getTotalTimeMillis() < 5000);
}
use of org.springframework.util.StopWatch in project spring-integration by spring-projects.
the class JdbcMessageStoreChannelOnePollerIntegrationTests method testSameTransactionDifferentChannelSendAndReceive.
@Test
public void testSameTransactionDifferentChannelSendAndReceive() throws Exception {
Service.reset(1);
assertNull(this.durable.receive(100L));
assertNull(this.relay.receive(100L));
final StopWatch stopWatch = new StopWatch();
boolean result = new TransactionTemplate(this.transactionManager).execute(status -> {
synchronized (this.storeLock) {
boolean result1 = this.relay.send(new GenericMessage<>("foo"), 500L);
// This will time out because the transaction has not committed yet
try {
Service.await(100);
fail("Expected timeout");
} catch (Exception e) {
// expected
}
try {
stopWatch.start();
// It hasn't arrive yet because we are still in the sending transaction
assertNull(this.durable.receive(100L));
} finally {
stopWatch.stop();
}
return result1;
}
});
assertTrue("Could not send message", result);
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
Service.await(10000);
// Eventual activation
assertEquals(1, Service.messages.size());
/*
* Without the storeLock:
*
* If we do this in a transaction it deadlocks occasionally. Without a transaction and it's pretty much every
* time.
*
* With the storeLock: It doesn't deadlock as long as the lock is injected into the poller as well.
*/
new TransactionTemplate(this.transactionManager).execute(status -> {
synchronized (this.storeLock) {
try {
stopWatch.start();
this.durable.receive(100L);
return null;
} finally {
stopWatch.stop();
}
}
});
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
}
use of org.springframework.util.StopWatch in project spring-integration by spring-projects.
the class JdbcMessageStoreChannelIntegrationTests method testSameTransactionSendAndReceive.
@Test
public void testSameTransactionSendAndReceive() {
final StopWatch stopWatch = new StopWatch();
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
// With a timeout on the transaction the test fails (after a long time) on the assertion in the transactional
// receive.
transactionDefinition.setTimeout(200);
boolean result = new TransactionTemplate(transactionManager, transactionDefinition).execute(status -> {
synchronized (storeLock) {
boolean result1 = input.send(new GenericMessage<String>("foo"), 500L);
// This will time out because the transaction has not committed yet
try {
Service.await(1000);
fail("Expected timeout");
} catch (Exception e) {
// expected
}
try {
stopWatch.start();
assertNotNull(input.receive(100L));
} finally {
stopWatch.stop();
}
return result1;
}
});
assertTrue("Could not send message", result);
// So no activation
assertEquals(0, Service.messages.size());
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 1000);
}
use of org.springframework.util.StopWatch in project cuba by cuba-platform.
the class ClusteredHttpInvokerRequestExecutor method doExecuteRequest.
@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
RemoteInvocationResult result;
Object context = serverSelector.initContext();
String url = currentServiceUrl(serverSelector.getUrl(context), config);
if (url == null)
throw new IllegalStateException("Server URL list is empty");
while (true) {
HttpURLConnection con = openConnection(url);
try {
StopWatch sw = new StopWatch();
prepareConnection(con, baos.size());
writeRequestBody(config, con, baos);
sw.start("waiting time");
validateResponse(config, con);
CountingInputStream responseInputStream = new CountingInputStream(readResponseBody(config, con));
sw.stop();
serverSelector.success(context);
sw.start("reading time");
try (ObjectInputStream ois = createObjectInputStream(decorateInputStream(responseInputStream), config.getCodebaseUrl())) {
result = doReadRemoteInvocationResult(ois);
}
sw.stop();
if (log.isDebugEnabled()) {
log.debug(String.format("Receiving HTTP invoker response for service at [%s], with size %s, %s", config.getServiceUrl(), responseInputStream.getCount(), printStopWatch(sw)));
}
break;
} catch (IOException e) {
log.info(String.format("Invocation of %s failed: %s", url, e));
serverSelector.fail(context);
url = currentServiceUrl(serverSelector.getUrl(context), config);
if (url != null) {
log.info("Trying to invoke the next available URL: " + url);
continue;
}
log.info("No more URL available");
throw e;
}
}
return result;
}
Aggregations