Fix Unlimited Queue Size Issue (#18633)

This commit is contained in:
Mohit Yadav 2024-11-13 22:02:34 +05:30 committed by GitHub
parent 128e4e8e93
commit ee327ce0c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 4 deletions

View File

@ -56,8 +56,8 @@ import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import lombok.Getter;
@ -161,7 +161,7 @@ public class SearchIndexApp extends AbstractNativeApplication {
private volatile boolean stopped = false;
private ExecutorService consumerExecutor;
private ExecutorService producerExecutor;
private final BlockingQueue<IndexingTask<?>> taskQueue = new LinkedBlockingQueue<>();
private BlockingQueue<IndexingTask<?>> taskQueue = new LinkedBlockingQueue<>(100);
private final AtomicReference<Stats> searchIndexStats = new AtomicReference<>();
private final AtomicReference<Integer> batchSize = new AtomicReference<>(5);
@ -286,8 +286,21 @@ public class SearchIndexApp extends AbstractNativeApplication {
int numConsumers = jobData.getConsumerThreads();
LOG.info("Starting reindexing with {} producers and {} consumers.", numProducers, numConsumers);
consumerExecutor = Executors.newFixedThreadPool(numConsumers);
producerExecutor = Executors.newFixedThreadPool(numProducers);
taskQueue = new LinkedBlockingQueue<>(jobData.getQueueSize());
consumerExecutor =
new ThreadPoolExecutor(
numConsumers,
numConsumers,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(jobData.getQueueSize()));
producerExecutor =
new ThreadPoolExecutor(
numProducers,
numProducers,
0L,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(jobData.getQueueSize()));
try {
processEntityReindex(jobExecutionContext);

View File

@ -50,6 +50,7 @@
"payLoadSize": 104857600,
"producerThreads": 1,
"consumerThreads": 1,
"queueSize": 100,
"maxConcurrentRequests": 100,
"maxRetries": 3,
"initialBackoff": 1000,

View File

@ -64,6 +64,7 @@
"batchSize": "100",
"payLoadSize": 104857600,
"producerThreads": 1,
"queueSize": 100,
"consumerThreads": 1,
"maxConcurrentRequests": 100,
"maxRetries": 3,

View File

@ -120,6 +120,12 @@
"type": "integer",
"default": 1
},
"queueSize": {
"title": "Queue Size to use.",
"description": "Queue Size to user internally for reindexing.",
"type": "integer",
"default": 100
},
"maxConcurrentRequests": {
"title": "Max Concurrent Requests",
"description": "Maximum number of concurrent requests to the search index",

View File

@ -28,6 +28,12 @@
"type": "integer",
"default": 1
},
"queueSize": {
"title": "Queue Size to use.",
"description": "Queue Size to user internally for reindexing.",
"type": "integer",
"default": 100
},
"maxConcurrentRequests": {
"title": "Max Concurrent Requests",
"description": "Maximum number of concurrent requests to the search index",