mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Idle-aware fallback trial batches
- Fallback trials budget a measured 128 MB each instead of 1 GB - Trial batches grow with idle hydrology workers up to the trial limit
This commit is contained in:
1 parent
c3b3f1d8aa
commit
4703d473cc
7 files changed
+105
-22
No files matched your search
+28
-7
@@ -20,14 +20,29 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
final class HydrologyCrossTileResolver {
|
||||
private static final int FALLBACK_TRIAL_PARALLELISM = 16;
|
||||
private static final int MINIMUM_FALLBACK_TRIAL_BATCH = 2;
|
||||
private final HydrologyPlanner planner;
|
||||
private final int trialLimit;
|
||||
|
||||
HydrologyCrossTileResolver(HydrologyPlanner planner) {
|
||||
HydrologyCrossTileResolver(HydrologyPlanner planner, int trialLimit) {
|
||||
if (trialLimit < 1) {
|
||||
throw new IllegalArgumentException("Hydrology fallback trial limit must be positive.");
|
||||
}
|
||||
this.planner = planner;
|
||||
this.trialLimit = trialLimit;
|
||||
}
|
||||
|
||||
static int fallbackTrialBatch(int parallelism, int idleWorkers, int trialLimit) {
|
||||
if (parallelism <= 2) {
|
||||
return 1;
|
||||
}
|
||||
int workers = Math.clamp(idleWorkers + 1L, MINIMUM_FALLBACK_TRIAL_BATCH, parallelism);
|
||||
return Math.max(1, Math.min(workers, Math.min(trialLimit, FALLBACK_TRIAL_PARALLELISM)));
|
||||
}
|
||||
|
||||
HydrologyOwnerDraft compileOwnerDraft(
|
||||
@@ -285,12 +300,18 @@ final class HydrologyCrossTileResolver {
|
||||
List<OutletCandidate> outlets,
|
||||
int start
|
||||
) {
|
||||
int parallelism = HydrologyPlanningAdmission.effectiveParallelism(
|
||||
Thread.currentThread() instanceof ForkJoinWorkerThread worker
|
||||
? worker.getPool().getParallelism()
|
||||
: IrisPlatforms.isBound() ? MultiBurst.hydrology.parallelism() : 1);
|
||||
int batchSize = parallelism <= 2 ? 1 : Math.max(1, Math.min(HydrologyPlanningAdmission.maximumTrials(),
|
||||
Math.min(FALLBACK_TRIAL_PARALLELISM, parallelism)));
|
||||
int parallelism;
|
||||
int idleWorkers;
|
||||
if (Thread.currentThread() instanceof ForkJoinWorkerThread worker) {
|
||||
ForkJoinPool pool = worker.getPool();
|
||||
parallelism = HydrologyPlanningAdmission.effectiveParallelism(pool.getParallelism());
|
||||
idleWorkers = pool.getParallelism() - pool.getActiveThreadCount();
|
||||
} else {
|
||||
parallelism = HydrologyPlanningAdmission.effectiveParallelism(
|
||||
IrisPlatforms.isBound() ? MultiBurst.hydrology.parallelism() : 1);
|
||||
idleWorkers = 0;
|
||||
}
|
||||
int batchSize = fallbackTrialBatch(parallelism, idleWorkers, trialLimit);
|
||||
int end = Math.min(outlets.size(), start + batchSize);
|
||||
ArrayList<Callable<FallbackTrial>> tasks = new ArrayList<>(end - start);
|
||||
HydrologyPlanner.PlanningSamples ownerSamples = planner.planningSamples.get();
|
||||
|
||||
@@ -197,7 +197,7 @@ public final class HydrologyPlanner {
|
||||
geometrySampler,
|
||||
settings.seaLevel()
|
||||
);
|
||||
this.crossTile = new HydrologyCrossTileResolver(this);
|
||||
this.crossTile = new HydrologyCrossTileResolver(this, HydrologyPlanningAdmission.maximumTrials());
|
||||
this.outletPlanner = new HydrologyOutletPlanner(this);
|
||||
this.sourcePlanner = new HydrologySourcePlanner(this);
|
||||
this.routeGeometry = new HydrologyRouteGeometry(this);
|
||||
|
||||
+3
-1
@@ -10,6 +10,8 @@ import java.util.function.BooleanSupplier;
|
||||
|
||||
final class HydrologyPlanningAdmission {
|
||||
private static final long BYTES_PER_ROOT = 2L * 1024L * 1024L * 1024L;
|
||||
private static final long BYTES_PER_TRIAL = 128L * 1024L * 1024L;
|
||||
private static final int MAXIMUM_TRIAL_LIMIT = 16;
|
||||
private static final int MAXIMUM_ROOTS = rootLimit(
|
||||
Runtime.getRuntime().maxMemory(), Runtime.getRuntime().availableProcessors());
|
||||
private static final int MAXIMUM_TRIALS = trialLimit(Runtime.getRuntime().maxMemory(), MAXIMUM_ROOTS);
|
||||
@@ -48,7 +50,7 @@ final class HydrologyPlanningAdmission {
|
||||
if (maximumRoots < 1) {
|
||||
throw new IllegalArgumentException("Maximum hydrology roots must be positive.");
|
||||
}
|
||||
return (int) Math.clamp(maximumHeap / maximumRoots / (1024L * 1024L * 1024L), 1L, 16L);
|
||||
return (int) Math.clamp(maximumHeap / maximumRoots / BYTES_PER_TRIAL, 1L, MAXIMUM_TRIAL_LIMIT);
|
||||
}
|
||||
|
||||
static int rootLimit(long maximumHeap, int processors) {
|
||||
|
||||
Reference in new issue
Block a user