This commit is contained in:
RePixelatedMC
2023-12-06 15:56:19 +01:00
parent 83e311870f
commit b5c1e7e2da
3 changed files with 107 additions and 71 deletions
@@ -5,6 +5,7 @@ import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
@@ -55,8 +56,13 @@ public class IrisEngineSVC implements IrisService {
try {
for (World world : IrisWorlds) {
Engine engine = IrisToolbelt.access(world).getEngine();
}
PlatformChunkGenerator generator = IrisToolbelt.access(Bukkit.getWorld("localmemtest"));
if (generator != null && generator.getEngine() != null) {
Engine engine = generator.getEngine();
engine.getMantle().trim();
} else {
Iris.info("localmemtest is nullmem");
}
} catch (Throwable e) {
Iris.reportError(e);
@@ -68,6 +74,7 @@ public class IrisEngineSVC implements IrisService {
}
};
}
public void IrisStartup(){
tectonicLimit.set(2);
long t = getHardware.getProcessMemory();
@@ -418,7 +418,6 @@ public class IrisEngine implements Engine {
J.a(() -> {
try {
getMantle().trim();
getData().getObjectLoader().clean();
} catch (Throwable e) {
Iris.reportError(e);
@@ -40,6 +40,7 @@ import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.Looper;
import lombok.Getter;
import org.bukkit.Chunk;
@@ -67,7 +68,9 @@ public class Mantle {
private final KSet<Long> unload;
private final AtomicBoolean closed;
private final MultiBurst ioBurst;
private final AtomicBoolean io;
private final AtomicBoolean ioTrim;
private final AtomicBoolean ioTectonicUnload;
public Looper ticker;
/**
* Create a new mantle
@@ -81,12 +84,19 @@ public class Mantle {
this.closed = new AtomicBoolean(false);
this.dataFolder = dataFolder;
this.worldHeight = worldHeight;
this.io = new AtomicBoolean(false);
this.ioTrim = new AtomicBoolean(false);
this.ioTectonicUnload = new AtomicBoolean(false);
dataFolder.mkdirs();
unload = new KSet<>();
loadedRegions = new KMap<>();
lastUse = new KMap<>();
ioBurst = MultiBurst.burst;
if (!ioTectonicUnload.get()) {
this.unloadTectonicPlate();
if (!ticker.isAlive()) {
ticker.start();
}
}
Iris.debug("Opened The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath());
}
@@ -393,13 +403,13 @@ public class Mantle {
private final AtomicDouble adjustedIdleDuration = new AtomicDouble(0);
public static final AtomicInteger tectonicLimit = new AtomicInteger(30);
@Getter
private final AtomicInteger dynamicThreads = new AtomicInteger(1);
private final AtomicInteger dynamicThreads = new AtomicInteger(4);
@Getter
private final AtomicInteger forceAggressiveThreshold = new AtomicInteger(30);
@Getter
private final AtomicLong oldestTectonicPlate = new AtomicLong(0);
@Getter
private final Set<Long> toUnload = new HashSet<>();
public Set<Long> toUnload = new HashSet<>();
private int g = 0;
/**
@@ -412,6 +422,7 @@ public class Mantle {
if (closed.get()) {
throw new RuntimeException("The Mantle is closed");
}
Iris.info(C.BLUE + "TECTONIC TRIM HAS RUN");
if (IrisSettings.get().getPerformance().getAggressiveTectonicThreshold() == -1) {
forceAggressiveThreshold.set(tectonicLimit.get());
} else {
@@ -419,6 +430,7 @@ public class Mantle {
}
// todo Repixel improve the logic
/*
int h = dynamicThreads.get() - 1;
if (toUnload.size() != 0) {
if (toUnload.size() > oldFakeToUnload.get()) {
@@ -443,6 +455,7 @@ public class Mantle {
} else {
dynamicThreads.set(IrisSettings.get().getPerformance().getTectonicUnloadThreads());
}
*/
adjustedIdleDuration.set(baseIdleDuration);
@@ -454,20 +467,23 @@ public class Mantle {
}
}
io.set(true);
ioTrim.set(true);
try {
Iris.debug("Trimming Tectonic Plates older than " + Form.duration(adjustedIdleDuration.get(), 0));
if (lastUse != null) {
for (Long i : lastUse.keySet()) {
Long lastUseTime = lastUse.get(i);
if (lastUseTime != null) {
double finalAdjustedIdleDuration = adjustedIdleDuration.get();
hyperLock.withLong(i, () -> {
if (M.ms() - lastUse.get(i) >= finalAdjustedIdleDuration) {
if (M.ms() - lastUseTime >= finalAdjustedIdleDuration) {
toUnload.add(i);
Iris.debug("Tectonic Region added to unload");
}
});
}
}
}
if (IrisSettings.get().getPerformance().AggressiveTectonicUnload
&& loadedRegions.size() > forceAggressiveThreshold.get()) {
@@ -503,7 +519,16 @@ public class Mantle {
}
}
}
} finally {
ioTrim.set(false);
}
}
protected void unloadTectonicPlate() {
ticker = new Looper() {
protected long loop() {
try {
Iris.info(C.DARK_BLUE + "TECTONIC UNLOAD HAS RUN");
BurstExecutor burstExecutor = new BurstExecutor(Executors.newFixedThreadPool(dynamicThreads.get()), toUnload.size());
for (Long i : toUnload.toArray(Long[]::new)) {
burstExecutor.queue(() -> {
@@ -515,7 +540,7 @@ public class Mantle {
loadedRegions.remove(i);
lastUse.remove(i);
toUnload.remove(i);
Iris.debug("Unloaded Tectonic Plate " + C.DARK_GREEN + Cache.keyX(i) + " " + Cache.keyZ(i));
Iris.info("Unloaded Tectonic Plate " + C.DARK_GREEN + Cache.keyX(i) + " " + Cache.keyZ(i));
} catch (IOException e) {
e.printStackTrace();
}
@@ -524,9 +549,14 @@ public class Mantle {
});
}
burstExecutor.complete();
} finally {
io.set(false);
} catch (Exception e){
Iris.reportError(e);
return -1;
}
return 1000;
}
};
ioTectonicUnload.set(true);
}
/**
@@ -539,7 +569,7 @@ public class Mantle {
*/
@RegionCoordinates
private TectonicPlate get(int x, int z) {
if (io.get()) {
if (ioTrim.get()) {
try {
return getSafe(x, z).get();
} catch (InterruptedException e) {