From 723f67ea0c77af19515c8da01303cd15be3766e7 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 10 May 2024 22:27:22 -0500 Subject: [PATCH] Attempt to prevent thread starvation due to world gen Hopefully this should help prevent issues on low end machines not loading in LODs --- .../GeneratedFullDataSourceProvider.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java index dc2abe9cf..da87e0128 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataSourceProvider.java @@ -47,7 +47,15 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im { private static final Logger LOGGER = DhLoggerBuilder.getLogger(); - public static final int MAX_WORLD_GEN_REQUESTS_PER_THREAD = 20; + /** + * Having this number too high causes the system to become overwhelmed by + * world gen requests and other jobs won't be done.
+ * IE: LODs won't update or render because world gen is hogging the CPU. + *

+ * TODO this should be dynamically allocated based on CPU load + * and abilities. + */ + public static final int MAX_WORLD_GEN_REQUESTS_PER_THREAD = 2; private final AtomicReference worldGenQueueRef = new AtomicReference<>(null); @@ -172,6 +180,15 @@ public class GeneratedFullDataSourceProvider extends FullDataSourceProviderV2 im } + ThreadPoolExecutor fileExecutor = ThreadPoolUtil.getFileHandlerExecutor(); + if (fileExecutor == null || fileExecutor.getQueue().size() >= MAX_UPDATE_TASK_COUNT / 2) + { + // don't queue additional world gen requests if the file handler is overwhelmed, + // otherwise LODs may not load in properly + return false; + } + + int maxQueueCount = MAX_WORLD_GEN_REQUESTS_PER_THREAD * Config.Client.Advanced.MultiThreading.numberOfWorldGenerationThreads.get(); if (this.delayedFullDataSourceSaveCache.getUnsavedCount() >= maxQueueCount)