Merge branch 'main' of gitlab.com:distant-horizons-team/distant-horizons-core

This commit is contained in:
James Seibel
2025-01-04 09:48:30 -06:00
4 changed files with 13 additions and 18 deletions
@@ -51,8 +51,6 @@ public abstract class AbstractDhServerLevel extends AbstractDhLevel implements I
private final FullDataSourceRequestHandler requestHandler = new FullDataSourceRequestHandler(this);
private final boolean NSizedGenerationSupported = false;
//=============//
// constructor //
@@ -217,8 +215,6 @@ public abstract class AbstractDhServerLevel extends AbstractDhLevel implements I
// world gen //
//===========//
public boolean isNSizedGenerationSupported() { return this.NSizedGenerationSupported; }
@Override
public void onWorldGenTaskComplete(long pos)
{
@@ -40,10 +40,7 @@ import org.apache.logging.log4j.Logger;
import javax.annotation.WillNotClose;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -426,7 +423,7 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
if (positionsToRequeue.contains(pos))
{
// don't attempt to re-load positions that are already in the process of reloading
break;
continue;
}
try
@@ -450,7 +447,6 @@ public class LodQuadTree extends QuadTree<LodRenderSection> implements IDebugRen
// if we don't trigger it again the LOD will be out of date
// and may be invisible/missing
positionsToRequeue.add(pos);
break;
}
}
}
@@ -2,9 +2,7 @@ package com.seibel.distanthorizons.core.util.threading;
import org.jetbrains.annotations.NotNull;
import java.util.Comparator;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.ReentrantLock;
@@ -67,12 +65,16 @@ public class PrioritySemaphore
// this has to be outside the try-finally to prevent holding the lock while waiting
synchronized (thread)
{
// random value between -5 and +5 is used to prevent task starvation
// while still allowing higher priority tasks to run sooner
int priority = executor.priority + this.random.nextInt(11) - 5;
// Calculation rules:
// - Executors with higher priority need less tasks to run before other executors
// If one executor has the priority of 3 and other if of 4,
// the latter one will need 1/4 fewer tasks in queue to get its tasks running
// - Executors with short-lived tasks run before longer lived ones
// 100k value is a multiplier to prevent precision loss
int priority = (int) ((executor.priority + 1) * executor.getTaskCount() * 100000 / executor.getAverageRunTimeInMs());
// this thread will be run when a permit is available
this.queue.put(new ThreadWithPriority(thread,priority));
this.queue.put(new ThreadWithPriority(thread, priority));
thread.wait();
}
@@ -92,8 +92,6 @@ public class RateLimitedThreadPoolExecutor extends ThreadPoolExecutor implements
@Override
protected void beforeExecute(Thread thread, Runnable runnable)
{
super.beforeExecute(thread, runnable);
long deltaMs = TimeUnit.NANOSECONDS.toMillis(this.lastRunDurationNanoTimeRef.get());
this.runTimeInMsRollingAverage.addValue(deltaMs);
@@ -124,12 +122,15 @@ public class RateLimitedThreadPoolExecutor extends ThreadPoolExecutor implements
this.runStartNanoTimeRef.set(System.nanoTime());
super.beforeExecute(thread, runnable);
}
@Override
protected void afterExecute(Runnable runnable, Throwable throwable)
{
super.afterExecute(runnable, throwable);
this.lastRunDurationNanoTimeRef.set(System.nanoTime() - this.runStartNanoTimeRef.get());