Skip to content

Commit

Permalink
fix(ChunkProcessingPipeline): base thread pool size on available proc…
Browse files Browse the repository at this point in the history
…essors
  • Loading branch information
keturn committed May 13, 2022
1 parent 789b392 commit c718ba7
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Terasology Foundation
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine.world.chunks.pipeline;
Expand Down Expand Up @@ -41,7 +41,8 @@
*/
public class ChunkProcessingPipeline {

private static final int NUM_TASK_THREADS = 4;
private static final int NUM_TASK_THREADS = Math.min(
Math.max(1, Runtime.getRuntime().availableProcessors() - 1), 8);
private static final Logger logger = LoggerFactory.getLogger(ChunkProcessingPipeline.class);

private final List<ChunkTaskProvider> stages = Lists.newArrayList();
Expand Down Expand Up @@ -71,6 +72,7 @@ protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
return new PositionFuture<>(newTaskFor, ((PositionalCallable) callable).getPosition());
}
};
logger.debug("allocated {} threads", NUM_TASK_THREADS);
chunkProcessor = new ExecutorCompletionService<>(executor,
new PriorityBlockingQueue<>(800, comparable));
reactor = new Thread(this::chunkTaskHandler);
Expand Down

0 comments on commit c718ba7

Please sign in to comment.