Skip to content

Commit 732b4fa

Browse files
authored
Merge pull request #189 from jacomago/skychunkingontop
Adds chunking to the processing
2 parents c05dc3c + 78cf2a9 commit 732b4fa

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorService.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import org.phoebus.channelfinder.entity.Channel;
44
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.beans.factory.annotation.Value;
56
import org.springframework.core.task.TaskExecutor;
67
import org.springframework.stereotype.Service;
78

9+
import java.util.ArrayList;
810
import java.util.List;
11+
import java.util.Spliterator;
912
import java.util.logging.Level;
1013
import java.util.logging.Logger;
1114
import java.util.stream.Collectors;
@@ -21,6 +24,9 @@ public class ChannelProcessorService {
2124
@Autowired
2225
private TaskExecutor taskExecutor;
2326

27+
@Value("processors.chunking.size")
28+
private int chunkSize;
29+
2430
long getProcessorCount() {
2531
return channelProcessors.size();
2632
}
@@ -44,9 +50,18 @@ public void sendToProcessors(List<Channel> channels) {
4450
}
4551
taskExecutor.execute(() -> channelProcessors.stream()
4652
.filter(ChannelProcessor::enabled)
53+
4754
.forEach(channelProcessor -> {
4855
try {
49-
channelProcessor.process(channels);
56+
Spliterator<Channel> split = channels.stream().spliterator();
57+
58+
while(true) {
59+
List<Channel> chunk = new ArrayList<>(chunkSize);
60+
for (int i = 0; i < chunkSize && split.tryAdvance(chunk::add); i++){};
61+
if (chunk.isEmpty()) break;
62+
channelProcessor.process(chunk);
63+
}
64+
5065
} catch (Exception e) {
5166
logger.log(Level.WARNING, "ChannelProcessor " + channelProcessor.getClass().getName() + " throws exception", e);
5267
}

src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ channelfinder.version=@project.version@
114114
# DEBUG level will log all requests and responses to and from the REST end points
115115
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=INFO
116116

117+
################ Processor ##################################################
118+
processors.chunking.size=10000
119+
117120
################ Archiver Appliance Configuration Processor #################
118121
aa.urls={'default': 'http://localhost:17665'}
119122
# Comma-separated list of archivers to use if archiver_property_name is null

0 commit comments

Comments
 (0)