This commit is contained in:
RePixelatedMC
2023-11-29 13:48:58 +01:00
parent f61247f8bb
commit 815b2235a2
2 changed files with 34 additions and 29 deletions
@@ -34,7 +34,7 @@ public class DynamicPerformanceSVC implements IrisService {
try { try {
if (engine.getMantle().getTectonicLimit() < engine.getMantle().getLoadedRegionCount()){ if (engine.getMantle().getTectonicLimit() < engine.getMantle().getLoadedRegionCount()){
// engine.getMantle().trim(5); // engine.getMantle().trim(5);
return 2000; // return 2000;
} }
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
@@ -42,7 +42,6 @@ import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.parallel.MultiBurst;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.checkerframework.checker.units.qual.A;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
@@ -415,10 +414,10 @@ public class Mantle {
if (closed.get()) { if (closed.get()) {
throw new RuntimeException("The Mantle is closed"); throw new RuntimeException("The Mantle is closed");
} }
if (forceAggressiveThreshold.get() != -1) { if (IrisSettings.get().getPerformance().getAggressiveTectonicThreshold() == -1) {
forceAggressiveThreshold.set(IrisSettings.get().getPerformance().getAggressiveTectonicThreshold());
} else {
forceAggressiveThreshold.set(tectonicLimit.get()); forceAggressiveThreshold.set(tectonicLimit.get());
} else {
forceAggressiveThreshold.set(IrisSettings.get().getPerformance().getAggressiveTectonicThreshold());
} }
if(IrisSettings.get().getPerformance().dynamicPerformanceMode) { if(IrisSettings.get().getPerformance().dynamicPerformanceMode) {
@@ -431,7 +430,9 @@ public class Mantle {
dynamicThreads.addAndGet(1); dynamicThreads.addAndGet(1);
} }
} else { } else {
g--; if (g > 0) {
g--;
}
} }
} else { } else {
if (dynamicThreads.get() >= 2) { if (dynamicThreads.get() >= 2) {
@@ -478,18 +479,22 @@ public class Mantle {
if (IrisSettings.get().getPerformance().AggressiveTectonicUnload if (IrisSettings.get().getPerformance().AggressiveTectonicUnload
&& loadedRegions.size() > forceAggressiveThreshold.get()) { && loadedRegions.size() > forceAggressiveThreshold.get()) {
while (loadedRegions.size() > tectonicLimit.get()) { AtomicInteger dummyLoadedRegions = new AtomicInteger(loadedRegions.size());
while (dummyLoadedRegions.get() > tectonicLimit.get()) {
Long[] oldestKey = {null}; Long[] oldestKey = {null};
long[] oldestAge = {Long.MIN_VALUE}; long[] oldestAge = {Long.MIN_VALUE};
for (Long key : lastUse.keySet()) { for (Long key : lastUse.keySet()) {
if (!toUnload.contains(key)) { hyperLock.withLong(key, () -> {
long age = M.ms() - lastUse.get(key); if (!toUnload.contains(key)) {
if (age > oldestAge[0]) { long age = M.ms() - lastUse.get(key);
oldestAge[0] = age; if (age > oldestAge[0]) {
oldestKey[0] = key; oldestAge[0] = age;
oldestKey[0] = key;
}
} }
} });
} }
if (oldestKey[0] != null) { if (oldestKey[0] != null) {
@@ -497,30 +502,30 @@ public class Mantle {
hyperLock.withLong(finalOldestKey, () -> { hyperLock.withLong(finalOldestKey, () -> {
toUnload.add(finalOldestKey); toUnload.add(finalOldestKey);
Iris.debug("Oldest Tectonic Region " + finalOldestKey + " added to unload"); Iris.debug("Oldest Tectonic Region " + finalOldestKey + " added to unload");
dummyLoadedRegions.getAndDecrement();
}); });
} }
} }
} }
BurstExecutor burstExecutor = new BurstExecutor(Executors.newFixedThreadPool(dynamicThreads.get()), toUnload.size()); BurstExecutor burstExecutor = new BurstExecutor(Executors.newFixedThreadPool(dynamicThreads.get()), toUnload.size());
for (Long i : toUnload.toArray(Long[]::new)) {
for (Long i : toUnload) { burstExecutor.queue(() -> {
burstExecutor.queue(() -> { hyperLock.withLong(i, () -> {
hyperLock.withLong(i, () -> { TectonicPlate m = loadedRegions.get(i);
TectonicPlate m = loadedRegions.get(i); if (m != null) {
if (m != null) { try {
try { m.write(fileForRegion(dataFolder, i));
m.write(fileForRegion(dataFolder, i)); loadedRegions.remove(i);
loadedRegions.remove(i); lastUse.remove(i);
lastUse.remove(i); toUnload.remove(i);
Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + Cache.keyX(i) + " " + Cache.keyZ(i)); Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + Cache.keyX(i) + " " + Cache.keyZ(i));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} });
}); });
});
} }
burstExecutor.complete(); burstExecutor.complete();
} finally { } finally {