Skip to content

Commit 8b3d3cd

Browse files
authored
Add new Parallel capable web consumer. Disabled by default (#170)
* Add new Parallel capable web consumer. Disabled by default * Re-use client instead of creating new instance * Enable multi-threaded consumer by default * Update README, CHANGELOG, and POM
1 parent 3ff7791 commit 8b3d3cd

File tree

16 files changed

+895
-344
lines changed

16 files changed

+895
-344
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 2.3.0 (UNRELEASED)
6+
#### New Features
7+
- [MultiThreaded Consumer](https://github.com/SourceLabOrg/kafka-webview/pull/170) Add multi-threaded kafka consumer.
8+
9+
Previously a single consumer instance was used when paging through messages from a topic. Each partition was consumed sequentially in order to provide consistent results on each page. For topics with a large number of partitions this could take considerable time.
10+
11+
The underlying consumer implementation has been replaced with a multi-threaded version which will attempt to read each partition in parallel. The following configuration properties have been added to control this behavior:
12+
13+
```yml
14+
app:
15+
## Enable multi-threaded consumer support
16+
## The previous single-threaded implementation is still available by setting this property to false.
17+
## The previous implementation along with this property will be removed in future release.
18+
multiThreadedConsumer: true
19+
20+
## Sets upper limit on the number of concurrent consumers (non-websocket) supported.
21+
maxConcurrentWebConsumers: 32
22+
```
23+
24+
If you run into issues, you can disable the new implementation and revert to the previous behavior by setting the `multiThreadedConsumer` property to `false`.
25+
526
## 2.2.0 (03/20/2019)
627

728
#### Bug fixes

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ app:
6767

6868
## Defines a prefix prepended to the Id of all consumers.
6969
consumerIdPrefix: "KafkaWebViewConsumer"
70+
71+
## Enable multi-threaded consumer support
72+
## The previous single-threaded implementation is still available by setting this property to false.
73+
## The previous implementation along with this property will be removed in future release.
74+
multiThreadedConsumer: true
75+
76+
## Sets upper limit on the number of concurrent consumers (non-websocket) supported.
77+
maxConcurrentWebConsumers: 32
7078

7179
## Sets upper limit on the number of concurrent web socket consumers supported.
7280
maxConcurrentWebSocketConsumers: 64
@@ -299,8 +307,8 @@ implementations.
299307
# Releasing
300308
Steps for performing a release:
301309
302-
1. Update release version: mvn versions:set -DnewVersion=X.Y.Z
303-
2. Validate and then commit version: mvn versions:commit
310+
1. Update release version: `mvn versions:set -DnewVersion=X.Y.Z`
311+
2. Validate and then commit version: `mvn versions:commit`
304312
3. Update CHANGELOG and README files.
305313
4. Merge to master.
306314
5. Deploy to Maven Central: mvn clean deploy -P release-kafka-webview

dev-cluster/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>kafka-webview</artifactId>
77
<groupId>org.sourcelab</groupId>
8-
<version>2.2.0</version>
8+
<version>2.3.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>dev-cluster</artifactId>
13-
<version>2.2.0</version>
13+
<version>2.3.0</version>
1414

1515
<!-- Require Maven 3.3.9 -->
1616
<prerequisites>

kafka-webview-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.sourcelab</groupId>
77
<artifactId>kafka-webview</artifactId>
8-
<version>2.2.0</version>
8+
<version>2.3.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-plugin</artifactId>

kafka-webview-ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<artifactId>kafka-webview</artifactId>
77
<groupId>org.sourcelab</groupId>
8-
<version>2.2.0</version>
8+
<version>2.3.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-ui</artifactId>
12-
<version>2.2.0</version>
12+
<version>2.3.0</version>
1313

1414
<!-- Module Description and Ownership -->
1515
<name>Kafka WebView UI</name>

kafka-webview-ui/src/assembly/distribution/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ app:
1616
## Defines a prefix prepended to the Id of all consumers.
1717
consumerIdPrefix: "KafkaWebViewConsumer"
1818

19+
## Enable multi-threaded consumer support
20+
## The previous single-threaded implementation is still available by setting this property to false.
21+
## The previous implementation along with this property will be removed in future release.
22+
multiThreadedConsumer: true
23+
24+
## Sets upper limit on the number of concurrent consumers (non-websocket) supported.
25+
maxConcurrentWebConsumers: 32
26+
1927
## Sets upper limit on the number of concurrent web socket consumers supported.
2028
maxConcurrentWebSocketConsumers: 64
2129

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/AppProperties.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public class AppProperties {
4343
@Value("${app.key}")
4444
private String appKey;
4545

46-
@Value("${app.maxConcurrentWebSocketConsumers}")
46+
@Value("${app.multiThreadedConsumer:true}")
47+
private boolean enableMultiThreadedConsumer;
48+
49+
@Value("${app.maxConcurrentWebConsumers:32}")
50+
private Integer maxConcurrentWebConsumers = 32;
51+
52+
@Value("${app.maxConcurrentWebSocketConsumers:100}")
4753
private Integer maxConcurrentWebSocketConsumers = 100;
4854

4955
@Value("${app.consumerIdPrefix}")
@@ -104,6 +110,14 @@ public boolean isAvroIncludeSchema() {
104110
return avroIncludeSchema;
105111
}
106112

113+
public boolean isEnableMultiThreadedConsumer() {
114+
return enableMultiThreadedConsumer;
115+
}
116+
117+
public Integer getMaxConcurrentWebConsumers() {
118+
return maxConcurrentWebConsumers;
119+
}
120+
107121
@Override
108122
public String toString() {
109123
return "AppProperties{"

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/PluginConfig.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
package org.sourcelab.kafka.webview.ui.configuration;
2626

2727
import com.fasterxml.jackson.databind.ObjectMapper;
28+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
2829
import com.hubspot.jackson.datatype.protobuf.ProtobufModule;
2930
import org.apache.kafka.common.serialization.Deserializer;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3033
import org.sourcelab.kafka.webview.ui.manager.encryption.SecretManager;
3134
import org.sourcelab.kafka.webview.ui.manager.kafka.KafkaAdminFactory;
3235
import org.sourcelab.kafka.webview.ui.manager.kafka.KafkaClientConfigUtil;
@@ -42,11 +45,15 @@
4245
import org.springframework.context.annotation.Bean;
4346
import org.springframework.stereotype.Component;
4447

48+
import java.util.concurrent.ExecutorService;
49+
import java.util.concurrent.Executors;
50+
4551
/**
4652
* Application Configuration for Plugin beans.
4753
*/
4854
@Component
4955
public class PluginConfig {
56+
private static final Logger logger = LoggerFactory.getLogger(PluginConfig.class);
5057

5158
/**
5259
* Upload manager, for handling uploads of Plugins and Keystores.
@@ -97,11 +104,30 @@ public SecretManager getSecretManager(final AppProperties appProperties) {
97104
*/
98105
@Bean
99106
public WebKafkaConsumerFactory getWebKafkaConsumerFactory(final AppProperties appProperties, final KafkaClientConfigUtil configUtil) {
107+
final ExecutorService executorService;
108+
109+
// If we have multi-threaded consumer option enabled
110+
if (appProperties.isEnableMultiThreadedConsumer()) {
111+
logger.info("Enabled multi-threaded webconsumer with {} threads.", appProperties.getMaxConcurrentWebConsumers());
112+
113+
// Create fixed thread pool
114+
executorService = Executors.newFixedThreadPool(
115+
appProperties.getMaxConcurrentWebConsumers(),
116+
new ThreadFactoryBuilder()
117+
.setNameFormat("kafka-web-consumer-pool-%d")
118+
.build()
119+
);
120+
} else {
121+
// Null reference.
122+
executorService = null;
123+
}
124+
100125
return new WebKafkaConsumerFactory(
101126
getDeserializerPluginFactory(appProperties),
102127
getRecordFilterPluginFactory(appProperties),
103128
getSecretManager(appProperties),
104-
getKafkaConsumerFactory(configUtil)
129+
getKafkaConsumerFactory(configUtil),
130+
executorService
105131
);
106132
}
107133

0 commit comments

Comments
 (0)