Skip to content

Commit b89fbc2

Browse files
refs #36: Clean up the performance testing to make it easier to switch implementation
1 parent d87c73d commit b89fbc2

File tree

6 files changed

+87
-39
lines changed

6 files changed

+87
-39
lines changed

examples/sqs-listener-library-comparison/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ This module has the Spring Cloud, JMS and Java Dynamic SQS Listener libraries al
33
to compare the performance of each of the types of libraries with different types of messages being processed. For example, a message that has a lot of
44
IO or to test what happens if the time to get new messages from the queue is large.
55

6+
## Getting Started
7+
You can run the [Application](src/main/java/com/jashmore/sqs/examples/Application.java) which will place messages onto a queue and then the corresponding
8+
listener will process them. Take a look at the [ExampleConstants](src/main/java/com/jashmore/sqs/examples/ExampleConstants.java) for the types of variables
9+
that can be altered, such as the time to process the messages, etc.
10+
611
## Results (02/June/2019)
712
The results that I ran on my local machine (which is not the greatest environment but gives a rough estimate) are the following:
813

examples/sqs-listener-library-comparison/src/main/java/com/jashmore/sqs/examples/ExampleConstants.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.jashmore.sqs.examples;
22

3+
import static com.jashmore.sqs.examples.Queues.PREFETCHING_30_QUEUE_NAME;
4+
35
import lombok.experimental.UtilityClass;
46

57
@UtilityClass
@@ -12,11 +14,15 @@ public class ExampleConstants {
1214
/**
1315
* The amount of time that the thread will be slept while processing the message. This will represent IO.
1416
*/
15-
public static final long MESSAGE_IO_TIME_IN_MS = 100;
17+
public static final long MESSAGE_IO_TIME_IN_MS = 500;
1618

1719
/**
1820
* The amount of time it takes to get a message from the remote SQS queue.
1921
*/
20-
public static final long MESSAGE_RETRIEVAL_LATENCY_IN_MS = 100;
22+
public static final long MESSAGE_RETRIEVAL_LATENCY_IN_MS = 200;
2123

24+
/**
25+
* The actual queue that messages will be placed onto during the test.
26+
*/
27+
public static final String QUEUE_TO_TEST = PREFETCHING_30_QUEUE_NAME;
2228
}

examples/sqs-listener-library-comparison/src/main/java/com/jashmore/sqs/examples/MessageListeners.java

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package com.jashmore.sqs.examples;
22

33
import static com.jashmore.sqs.examples.ExampleConstants.MESSAGE_IO_TIME_IN_MS;
4+
import static com.jashmore.sqs.examples.Queues.JMS_10_QUEUE_NAME;
5+
import static com.jashmore.sqs.examples.Queues.JMS_30_QUEUE_NAME;
6+
import static com.jashmore.sqs.examples.Queues.PREFETCHING_10_QUEUE_NAME;
7+
import static com.jashmore.sqs.examples.Queues.PREFETCHING_30_QUEUE_NAME;
8+
import static com.jashmore.sqs.examples.Queues.QUEUE_LISTENER_10_QUEUE_NAME;
9+
import static com.jashmore.sqs.examples.Queues.QUEUE_LISTENER_30_QUEUE_NAME;
10+
import static com.jashmore.sqs.examples.Queues.SPRING_CLOUD_QUEUE_NAME;
411

512
import com.jashmore.sqs.argument.payload.Payload;
13+
import com.jashmore.sqs.spring.container.basic.QueueListener;
614
import com.jashmore.sqs.spring.container.prefetch.PrefetchingQueueListener;
715
import lombok.extern.slf4j.Slf4j;
16+
import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
17+
import org.springframework.jms.annotation.JmsListener;
818
import org.springframework.stereotype.Component;
919

1020
import java.util.concurrent.atomic.AtomicInteger;
@@ -13,7 +23,7 @@
1323
/**
1424
* Each of the types of messages listeners that are available.
1525
*
16-
* <p>To test a different implementation, uncomment it and comment out the current one as you should only have one running at a time.
26+
* <p>If you want a true performance test you should remove all of the other listener implementations so that they don't impact each other.
1727
*/
1828
@Component
1929
@SuppressWarnings("unused")
@@ -22,40 +32,40 @@ public class MessageListeners {
2232
private final AtomicInteger count = new AtomicInteger(0);
2333
private final AtomicLong firstTime = new AtomicLong(0);
2434

25-
//@PrefetchingQueueListener(value = "queueName", concurrencyLevel = 10, desiredMinPrefetchedMessages = 50, maxPrefetchedMessages = 60)
26-
//public void prefetchingConcurrency10(@Payload final String payload) throws Exception {
27-
// handleMethod();
28-
//}
35+
@PrefetchingQueueListener(value = PREFETCHING_10_QUEUE_NAME, concurrencyLevel = 10, desiredMinPrefetchedMessages = 50, maxPrefetchedMessages = 60)
36+
public void prefetchingConcurrency10(@Payload final String payload) throws Exception {
37+
handleMethod();
38+
}
2939

30-
@PrefetchingQueueListener(value = "queueName", concurrencyLevel = 30, desiredMinPrefetchedMessages = 50, maxPrefetchedMessages = 60)
40+
@PrefetchingQueueListener(value = PREFETCHING_30_QUEUE_NAME, concurrencyLevel = 30, desiredMinPrefetchedMessages = 50, maxPrefetchedMessages = 60)
3141
public void prefetchingConcurrency30(@Payload final String payload) throws Exception {
3242
handleMethod();
3343
}
3444

35-
//@QueueListener(value = "queueName", concurrencyLevel = 10)
36-
//public void queueListenerMethodConcurrency10(@Payload final String payload) throws Exception {
37-
// handleMethod();
38-
//}
45+
@QueueListener(value = QUEUE_LISTENER_10_QUEUE_NAME, concurrencyLevel = 10)
46+
public void queueListenerMethodConcurrency10(@Payload final String payload) throws Exception {
47+
handleMethod();
48+
}
49+
50+
@QueueListener(value = QUEUE_LISTENER_30_QUEUE_NAME, concurrencyLevel = 30)
51+
public void queueListenerMethodConcurrency30(@Payload final String payload) throws Exception {
52+
handleMethod();
53+
}
3954

40-
//@QueueListener(value = "queueName", concurrencyLevel = 30)
41-
//public void queueListenerMethodConcurrency30(@Payload final String payload) throws Exception {
42-
// handleMethod();
43-
//}
44-
//
45-
//@SqsListener("queueName")
46-
//public void springCloudConcurrency10(final String payload) throws Exception {
47-
// handleMethod();
48-
//}
49-
//
50-
//@JmsListener(destination = "queueName", concurrency = "10")
51-
//public void jmsConcurrency10(String message) throws Exception {
52-
// handleMethod();
53-
//}
54-
//
55-
//@JmsListener(destination = "queueName", concurrency = "30")
56-
//public void jmsConcurrency30(String message) throws Exception {
57-
// handleMethod();
58-
//}
55+
@SqsListener(SPRING_CLOUD_QUEUE_NAME)
56+
public void springCloudConcurrency10(final String payload) throws Exception {
57+
handleMethod();
58+
}
59+
60+
@JmsListener(destination = JMS_10_QUEUE_NAME, concurrency = "10")
61+
public void jmsConcurrency10(String message) throws Exception {
62+
handleMethod();
63+
}
64+
65+
@JmsListener(destination = JMS_30_QUEUE_NAME, concurrency = "30")
66+
public void jmsConcurrency30(String message) throws Exception {
67+
handleMethod();
68+
}
5969

6070
private void handleMethod() throws Exception {
6171
firstTime.compareAndSet(0, System.currentTimeMillis());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.jashmore.sqs.examples;
2+
3+
import lombok.experimental.UtilityClass;
4+
5+
@UtilityClass
6+
public class Queues {
7+
public static final String PREFETCHING_10_QUEUE_NAME = "prefetching10";
8+
public static final String PREFETCHING_30_QUEUE_NAME = "prefetching30";
9+
public static final String QUEUE_LISTENER_10_QUEUE_NAME = "queueListener10";
10+
public static final String QUEUE_LISTENER_30_QUEUE_NAME = "queueListener30";
11+
public static final String SPRING_CLOUD_QUEUE_NAME = "spring";
12+
public static final String JMS_10_QUEUE_NAME = "jms10";
13+
public static final String JMS_30_QUEUE_NAME = "jms30";
14+
}

examples/sqs-listener-library-comparison/src/main/java/com/jashmore/sqs/examples/SqsListenersConfiguration.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package com.jashmore.sqs.examples;
22

33
import static com.jashmore.sqs.examples.ExampleConstants.NUMBER_OF_MESSAGES;
4+
import static com.jashmore.sqs.examples.ExampleConstants.QUEUE_TO_TEST;
5+
import static com.jashmore.sqs.examples.Queues.JMS_10_QUEUE_NAME;
6+
import static com.jashmore.sqs.examples.Queues.JMS_30_QUEUE_NAME;
7+
import static com.jashmore.sqs.examples.Queues.PREFETCHING_10_QUEUE_NAME;
8+
import static com.jashmore.sqs.examples.Queues.PREFETCHING_30_QUEUE_NAME;
9+
import static com.jashmore.sqs.examples.Queues.QUEUE_LISTENER_10_QUEUE_NAME;
10+
import static com.jashmore.sqs.examples.Queues.QUEUE_LISTENER_30_QUEUE_NAME;
11+
import static com.jashmore.sqs.examples.Queues.SPRING_CLOUD_QUEUE_NAME;
412
import static java.util.stream.Collectors.toSet;
513

614
import akka.http.scaladsl.Http;
@@ -72,12 +80,18 @@ public SqsAsyncClient sqsAsyncClient(SQSRestServer sqsRestServer) throws Excepti
7280
final LocalSqsAsyncClient localSqsAsyncClient = new LocalSqsAsyncClient(SqsQueuesConfig
7381
.builder()
7482
.sqsServerUrl("http://localhost:" + serverBinding.localAddress().getPort())
75-
.queue(SqsQueuesConfig.QueueConfig.builder().queueName("queueName").build())
83+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(JMS_10_QUEUE_NAME).build())
84+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(JMS_30_QUEUE_NAME).build())
85+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(SPRING_CLOUD_QUEUE_NAME).build())
86+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(PREFETCHING_10_QUEUE_NAME).build())
87+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(PREFETCHING_30_QUEUE_NAME).build())
88+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(QUEUE_LISTENER_10_QUEUE_NAME).build())
89+
.queue(SqsQueuesConfig.QueueConfig.builder().queueName(QUEUE_LISTENER_30_QUEUE_NAME).build())
7690
.build());
7791

7892
localSqsAsyncClient.buildQueues();
7993

80-
sendMessagesToQueue(localSqsAsyncClient, "queueName", NUMBER_OF_MESSAGES);
94+
sendMessagesToQueue(localSqsAsyncClient);
8195

8296
return new LatencyAppliedSqsAsyncClient(localSqsAsyncClient);
8397
}
@@ -86,6 +100,7 @@ public SqsAsyncClient sqsAsyncClient(SQSRestServer sqsRestServer) throws Excepti
86100
* Creates a SQS Client for the Spring Cloud and JMS SQS Listener Libraries.
87101
*
88102
* @param sqsRestServer the sqs server
103+
* @param ignored depend on the client as that is what actually builds the queue and places the messages on it
89104
* @return client for communicating with the local SQS
90105
*/
91106
@Bean
@@ -158,11 +173,9 @@ public JmsListenerContainerFactory<DefaultMessageListenerContainer> jmsListenerC
158173
return factory;
159174
}
160175

161-
private void sendMessagesToQueue(final SqsAsyncClient sqsAsyncClient,
162-
final String queueName,
163-
final int messageCount) throws ExecutionException, InterruptedException {
164-
final String queueUrl = sqsAsyncClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(queueName).build()).get().queueUrl();
165-
for (int i = 0; i < messageCount; i = i + 10) {
176+
private void sendMessagesToQueue(final SqsAsyncClient sqsAsyncClient) throws ExecutionException, InterruptedException {
177+
final String queueUrl = sqsAsyncClient.getQueueUrl(GetQueueUrlRequest.builder().queueName(QUEUE_TO_TEST).build()).get().queueUrl();
178+
for (int i = 0; i < NUMBER_OF_MESSAGES; i = i + 10) {
166179
final int base = i;
167180

168181
final SendMessageBatchRequest.Builder batchRequestBuilder = SendMessageBatchRequest.builder().queueUrl(queueUrl);

examples/sqs-listener-library-comparison/src/main/java/com/jashmore/sqs/examples/latency/LatencyAppliedAmazonSqsAsync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LatencyAppliedAmazonSqsAsync implements AmazonSQSAsync {
1515
@Delegate(excludes = MethodsToOverride.class)
1616
private final AmazonSQSAsync delegate;
1717

18-
//@Override
18+
@Override
1919
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest request) {
2020
try {
2121
// Let's pretend there is some latency

0 commit comments

Comments
 (0)