Skip to content

Commit 5435c7b

Browse files
e-pettersson-ericssonm-linner-ericssonChristoffer-CortesSantoshNC68
authored
Use threadpool for subscription checking (#465)
- Add thread pool for SubscriptionHandler - Setup threadpool settings for SubscriptionHandler in SpringAsyncConfig - Add new properties for subscription handler thread pool with same values as event handler thread pool - Update test and info to use new properties - Set org.mongodb.driver.protocol.command log out to error - Fix of docker-compose correct path to rules - Add config for subscription handler execution pool in tests * Step patch version to 2.0.1 * Update default values to match eventhandler threadpool Co-authored-by: Mattias Linner <mattias.linner@ericsson.com> Co-authored-by: Christoffer Cortes Sjöwall <35095827+Christoffer-Cortes@users.noreply.github.com> Co-authored-by: SantoshNC68 <nc.santosh@tcs.com>
1 parent 01a661f commit 5435c7b

File tree

11 files changed

+132
-94
lines changed

11 files changed

+132
-94
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.ericsson</groupId>
88
<artifactId>eiffel-intelligence</artifactId>
9-
<version>2.2.0</version>
9+
<version>2.2.1</version>
1010
<packaging>war</packaging>
1111

1212
<parent>

src/functionaltests/java/com/ericsson/ei/threadingAndWaitlistRepeat/ThreadingAndWaitlistRepeatSteps.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"threads.corePoolSize= 3",
3030
"threads.queueCapacity= 1",
3131
"threads.maxPoolSize= 4",
32+
"subscription-handler.threads.corePoolSize= 3",
33+
"subscription-handler.threads.queueCapacity= 1",
34+
"subscription-handler.threads.maxPoolSize= 4",
3235
"waitlist.collection.ttlValue: 60",
3336
"waitlist.initialDelayResend= 500",
3437
"waitlist.fixedRateResend= 1000",
@@ -46,12 +49,7 @@ public class ThreadingAndWaitlistRepeatSteps extends FunctionalTestBase {
4649
@Autowired
4750
private Environment environment;
4851

49-
@Value("${threads.corePoolSize}")
50-
private int corePoolSize;
51-
@Value("${threads.queueCapacity}")
52-
private int queueCapacity;
53-
@Value("${threads.maxPoolSize}")
54-
private int maxPoolSize;
52+
5553
@Value("${waitlist.collection.ttlValue}")
5654
private int waitlistTtl;
5755

@@ -64,41 +62,41 @@ public class ThreadingAndWaitlistRepeatSteps extends FunctionalTestBase {
6462

6563
@Given("^that eiffel events are sent$")
6664
public void that_eiffel_events_are_sent() throws Throwable {
67-
List<String> eventNamesToSend = getEventNamesToSend();
65+
final List<String> eventNamesToSend = getEventNamesToSend();
6866
eventManager.sendEiffelEvents(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend);
6967
}
7068

7169
@Then("^waitlist should not be empty$")
7270
public void waitlist_should_not_be_empty() throws Throwable {
7371
TimeUnit.SECONDS.sleep(5);
74-
int waitListSize = dbManager.waitListSize();
72+
final int waitListSize = dbManager.waitListSize();
7573
assertNotEquals(0, waitListSize);
7674
}
7775

7876
@Given("^no event is aggregated$")
7977
public void no_event_is_aggregated() throws Throwable {
80-
boolean aggregatedObjectExists = dbManager.verifyAggregatedObjectExistsInDB();
78+
final boolean aggregatedObjectExists = dbManager.verifyAggregatedObjectExistsInDB();
8179
assertEquals("aggregatedObjectExists was true, should be false, ", false, aggregatedObjectExists);
8280
}
8381

8482
@Then("^event-to-object-map is manipulated to include the sent events$")
8583
public void event_to_object_map_is_manipulated_to_include_the_sent_events() throws Throwable {
86-
JsonNode parsedJSON = eventManager.getJSONFromFile(EIFFEL_EVENTS_JSON_PATH);
87-
ObjectMapper objectMapper = new ObjectMapper();
84+
final JsonNode parsedJSON = eventManager.getJSONFromFile(EIFFEL_EVENTS_JSON_PATH);
85+
final ObjectMapper objectMapper = new ObjectMapper();
8886
rulesJson = objectMapper.readTree(ID_RULE);
8987
rulesObject = new RulesObject(rulesJson);
9088

91-
String dummyObjectID = "1234abcd-12ab-12ab-12ab-123456abcdef";
92-
List<String> eventNames = getEventNamesToSend();
93-
for (String eventName : eventNames) {
94-
JsonNode eventJson = parsedJSON.get(eventName);
89+
final String dummyObjectID = "1234abcd-12ab-12ab-12ab-123456abcdef";
90+
final List<String> eventNames = getEventNamesToSend();
91+
for (final String eventName : eventNames) {
92+
final JsonNode eventJson = parsedJSON.get(eventName);
9593
eventToObjectMapHanler.updateEventToObjectMapInMemoryDB(rulesObject, eventJson.toString(), dummyObjectID);
9694
}
9795
}
9896

9997
@Then("^when waitlist has resent events they should have been deleted$")
10098
public void when_waitlist_has_resent_events_they_should_have_been_deleted() throws Throwable {
101-
long stopTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3);
99+
final long stopTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3);
102100
while (dbManager.waitListSize() > 0 && stopTime > System.currentTimeMillis()) {
103101
TimeUnit.MILLISECONDS.sleep(100);
104102
}
@@ -108,19 +106,19 @@ public void when_waitlist_has_resent_events_they_should_have_been_deleted() thro
108106

109107
@Then("^after the time to live has ended, the waitlist should be empty$")
110108
public void after_the_time_to_live_has_ended_the_waitlist_should_be_empty() throws Throwable {
111-
long stopTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(waitlistTtl + 60);
109+
final long stopTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(waitlistTtl + 60);
112110
while (dbManager.waitListSize() > 0 && stopTime > System.currentTimeMillis()) {
113111
TimeUnit.MILLISECONDS.sleep(10000);
114112
}
115-
int waitListSize = dbManager.waitListSize();
113+
final int waitListSize = dbManager.waitListSize();
116114
assertEquals(0, waitListSize);
117115
}
118116

119117
/**
120118
* Events used in the aggregation.
121119
*/
122120
protected List<String> getEventNamesToSend() {
123-
List<String> eventNames = new ArrayList<>();
121+
final List<String> eventNames = new ArrayList<>();
124122
eventNames.add("event_EiffelConfidenceLevelModifiedEvent_3_2");
125123
eventNames.add("event_EiffelArtifactPublishedEvent_3");
126124
eventNames.add("event_EiffelTestCaseTriggeredEvent_3");

src/main/docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ services:
183183
environment: # Overrides settings in application config file
184184
- SpringApplicationName=eiffel-intelligence-backend
185185
- server.port=8080
186-
- rules.path=src/main/resources/ArtifactRules.json
186+
- rules.path=/rules/ArtifactRules-Eiffel-Agen-Version.json
187187
- rabbitmq.host=rabbitmq
188188
- rabbitmq.port=${RABBITMQ_AMQP_PORT}
189189
- rabbitmq.domainId=ei-domain

src/main/java/com/ericsson/ei/config/ConfigurationLogger.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ private void logConfiguration() {
5757
+ "threads.corePoolSize: " + env.getProperty("threads.corePoolSize") + "\n"
5858
+ "threads.queueCapacity: " + env.getProperty("threads.queueCapacity") + "\n"
5959
+ "threads.maxPoolSize: " + env.getProperty("threads.maxPoolSize") + "\n"
60+
+ "subscription-handler.threads.corePoolSize: " + env.getProperty("subscription-handler.threads.corePoolSize") + "\n"
61+
+ "subscription-handler.threads.queueCapacity: " + env.getProperty("subscription-handler.threads.queueCapacity") + "\n"
62+
+ "subscription-handler.threads.maxPoolSize: " + env.getProperty("subscription-handler.threads.maxPoolSize") + "\n"
6063
+ "missedNotificationCollectionName: " + env.getProperty("missedNotificationCollectionName") + "\n"
6164
+ "missedNotificationDataBaseName: " + env.getProperty("missedNotificationDataBaseName") + "\n"
6265
+ "email.sender: " + env.getProperty("email.sender") + "\n"

src/main/java/com/ericsson/ei/config/SpringAsyncConfig.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
2222
import org.springframework.beans.factory.annotation.Value;
23+
import org.springframework.context.annotation.Bean;
2324
import org.springframework.context.annotation.Configuration;
2425
import org.springframework.scheduling.annotation.AsyncConfigurer;
2526
import org.springframework.scheduling.annotation.EnableAsync;
@@ -29,23 +30,49 @@
2930
@EnableAsync
3031
public class SpringAsyncConfig implements AsyncConfigurer{
3132

32-
@Value("${threads.corePoolSize}") private int corePoolSize;
33-
@Value("${threads.queueCapacity}") private int queueCapacity;
34-
@Value("${threads.maxPoolSize}") private int maxPoolSize;
3533

34+
@Value("${threads.corePoolSize}")
35+
private int eventHandlerCorePoolSize;
3636

37-
@Override
38-
public Executor getAsyncExecutor() {
39-
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
40-
executor.setCorePoolSize(corePoolSize);
41-
executor.setQueueCapacity(queueCapacity);
42-
executor.setMaxPoolSize(maxPoolSize);
43-
executor.setThreadNamePrefix("EventHandler-");
37+
@Value("${threads.queueCapacity}")
38+
private int eventHandlerQueueCapacity;
39+
40+
@Value("${threads.maxPoolSize}")
41+
private int eventHandlerMaxPoolSize;
42+
43+
@Value("${subscription-handler.threads.corePoolSize:50}")
44+
private int subscriptionHandlerCorePoolSize;
45+
46+
@Value("${subscription-handler.threads.queueCapacity:5000}")
47+
private int subscriptionHandlerQueueCapacity;
48+
49+
@Value("${subscription-handler.threads.maxPoolSize:50}")
50+
private int subscriptionHandlerMaxPoolSize;
51+
52+
53+
@Bean("subscriptionHandlerExecutor")
54+
public Executor subscriptionHandlerExecutor() {
55+
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
56+
executor.setCorePoolSize(subscriptionHandlerCorePoolSize);
57+
executor.setQueueCapacity(subscriptionHandlerQueueCapacity);
58+
executor.setMaxPoolSize(subscriptionHandlerMaxPoolSize);
59+
executor.setThreadNamePrefix("SubscriptionHandler-");
4460
executor.initialize();
4561
return executor;
4662
}
4763

4864

65+
@Bean("eventHandlerExecutor")
66+
public Executor eventHandlerExecutor() {
67+
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
68+
executor.setCorePoolSize(eventHandlerCorePoolSize);
69+
executor.setQueueCapacity(eventHandlerQueueCapacity);
70+
executor.setMaxPoolSize(eventHandlerMaxPoolSize);
71+
executor.setThreadNamePrefix("EventHandler-");
72+
executor.initialize();
73+
return executor;
74+
}
75+
4976
@Override
5077
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
5178
// TODO Auto-generated method stub

src/main/java/com/ericsson/ei/controller/model/ParseInstanceInfoEI.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public class ParseInstanceInfoEI {
109109

110110
@PostConstruct
111111
public void init() throws IOException {
112-
Properties properties = new Properties();
112+
final Properties properties = new Properties();
113113
properties.load(
114114
ParseInstanceInfoEI.class.getResourceAsStream("/default-application.properties"));
115115
version = properties.getProperty("version");
@@ -184,14 +184,26 @@ public void init() throws IOException {
184184
private class ThreadsValue {
185185
@Getter
186186
@Value("${threads.corePoolSize}")
187-
private int corePoolSize;
187+
private int eventHandlerCorePoolSize;
188188

189189
@Getter
190190
@Value("${threads.queueCapacity}")
191-
private int queueCapacity;
191+
private int eventHandlerQueueCapacity;
192192

193193
@Getter
194194
@Value("${threads.maxPoolSize}")
195-
private int maxPoolSize;
195+
private int eventHandlerMaxPoolSize;
196+
197+
@Getter
198+
@Value("${subscription-handler.threads.corePoolSize}")
199+
private int subscriptionHandlerCorePoolSize;
200+
201+
@Getter
202+
@Value("${subscription-handler.threads.queueCapacity}")
203+
private int subscriptionHandlerQueueCapacity;
204+
205+
@Getter
206+
@Value("${subscription-handler.threads.maxPoolSize}")
207+
private int subscriptionHandlerMaxPoolSize;
196208
}
197209
}

src/main/java/com/ericsson/ei/handlers/EventHandler.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ public RulesHandler getRulesHandler() {
5151
return rulesHandler;
5252
}
5353

54-
public void eventReceived(String event) {
55-
RulesObject eventRules = rulesHandler.getRulesForEvent(event);
54+
public void eventReceived(final String event) {
55+
final RulesObject eventRules = rulesHandler.getRulesForEvent(event);
5656
idRulesHandler.runIdRules(eventRules, event);
5757
}
5858

59-
@Async
60-
public void onMessage(Message message, Channel channel) throws Exception {
61-
String messageBody = new String(message.getBody());
62-
ObjectMapper objectMapper = new ObjectMapper();
63-
JsonNode node = objectMapper.readTree(messageBody);
64-
String id = node.get("meta").get("id").toString();
59+
@Async("eventHandlerExecutor")
60+
public void onMessage(final Message message, final Channel channel) throws Exception {
61+
final String messageBody = new String(message.getBody());
62+
final ObjectMapper objectMapper = new ObjectMapper();
63+
final JsonNode node = objectMapper.readTree(messageBody);
64+
final String id = node.get("meta").get("id").toString();
6565
LOGGER.debug("Thread id {} spawned for EventHandler", Thread.currentThread().getId());
6666
LOGGER.debug("Event {} received", id);
6767

6868
eventReceived(messageBody);
69-
long deliveryTag = message.getMessageProperties().getDeliveryTag();
69+
final long deliveryTag = message.getMessageProperties().getDeliveryTag();
7070
channel.basicAck(deliveryTag, false);
7171

7272
LOGGER.debug("Event {} processed", id);

src/main/java/com/ericsson/ei/handlers/RmqHandler.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public ConnectionFactory connectionFactory() {
135135
try {
136136
LOGGER.debug("Using SSL/TLS version {} connection to RabbitMQ.", tlsVersion);
137137
cachingConnectionFactory.getRabbitConnectionFactory().useSslProtocol(tlsVersion);
138-
} catch (Exception e) {
138+
} catch (final Exception e) {
139139
LOGGER.error("Failed to set SSL/TLS version.", e);
140140
}
141141
}
@@ -172,19 +172,19 @@ Binding binding() {
172172

173173
@Bean
174174
public List<Binding> bindings() {
175-
String[] bingingKeysArray = splitBindingKeys(bindingKeys);
176-
List<Binding> bindingList = new ArrayList<Binding>();
177-
for (String bindingKey : bingingKeysArray) {
175+
final String[] bingingKeysArray = splitBindingKeys(bindingKeys);
176+
final List<Binding> bindingList = new ArrayList<>();
177+
for (final String bindingKey : bingingKeysArray) {
178178
bindingList.add(BindingBuilder.bind(externalQueue()).to(exchange()).with(bindingKey));
179179
}
180180
return bindingList;
181181
}
182182

183183
@Bean
184184
public SimpleMessageListenerContainer bindToQueueForRecentEvents(
185-
ConnectionFactory springConnectionFactory,
186-
EventHandler eventHandler) {
187-
MessageListenerAdapter listenerAdapter = new EIMessageListenerAdapter(eventHandler);
185+
final ConnectionFactory springConnectionFactory,
186+
final EventHandler eventHandler) {
187+
final MessageListenerAdapter listenerAdapter = new EIMessageListenerAdapter(eventHandler);
188188
container = new SimpleMessageListenerContainer();
189189
container.setConnectionFactory(springConnectionFactory);
190190
container.setQueueNames(getQueueName(), getWaitlistQueueName());
@@ -214,7 +214,7 @@ public RabbitTemplate rabbitMqTemplate() {
214214
rabbitTemplate.setRoutingKey(getWaitlistQueueName());
215215
rabbitTemplate.setConfirmCallback(new ConfirmCallback() {
216216
@Override
217-
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
217+
public void confirm(final CorrelationData correlationData, final boolean ack, final String cause) {
218218
LOGGER.info("Received confirm with result : {}", ack);
219219
}
220220
});
@@ -223,18 +223,18 @@ public void confirm(CorrelationData correlationData, boolean ack, String cause)
223223
}
224224

225225
public String getQueueName() {
226-
String durableName = queueDurable ? "durable" : "transient";
226+
final String durableName = queueDurable ? "durable" : "transient";
227227
return domainId + "." + componentName + "." + consumerName + "." + durableName;
228228
}
229229

230230
public String getWaitlistQueueName() {
231231

232-
String durableName = queueDurable ? "durable" : "transient";
232+
final String durableName = queueDurable ? "durable" : "transient";
233233
return domainId + "." + componentName + "." + consumerName + "." + durableName + "."
234234
+ waitlistSufix;
235235
}
236236

237-
public void publishObjectToWaitlistQueue(String message) {
237+
public void publishObjectToWaitlistQueue(final String message) {
238238
LOGGER.debug("Publishing message to message bus...");
239239
rabbitTemplate.convertAndSend(message);
240240
}
@@ -243,13 +243,13 @@ public void close() {
243243
try {
244244
container.destroy();
245245
cachingConnectionFactory.destroy();
246-
} catch (Exception e) {
246+
} catch (final Exception e) {
247247
LOGGER.error("Exception occurred while closing connections.", e);
248248
}
249249
}
250250

251-
private String[] splitBindingKeys(String bindingKeys) {
252-
String bindingKeysWithoutWhitespace = bindingKeys.replaceAll("\\s+", "");
251+
private String[] splitBindingKeys(final String bindingKeys) {
252+
final String bindingKeysWithoutWhitespace = bindingKeys.replaceAll("\\s+", "");
253253
return bindingKeysWithoutWhitespace.split(",");
254254
}
255255
}

0 commit comments

Comments
 (0)