mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-02-16 10:30:53 +00:00
Merge pull request #10 from CrazyDev05/Pixeldev
Fix lastUse and Implement MultiBurst
This commit is contained in:
@@ -22,7 +22,7 @@ import java.util.function.Supplier;
|
||||
public class IrisEngineSVC implements IrisService {
|
||||
private static final AtomicInteger tectonicLimit = new AtomicInteger(30);
|
||||
private final ReentrantLock lastUseLock = new ReentrantLock();
|
||||
private final KMap<Engine, Long> lastUse = new KMap<>();
|
||||
private final KMap<World, Long> lastUse = new KMap<>();
|
||||
private Looper cacheTicker;
|
||||
private Looper trimTicker;
|
||||
private Looper unloadTicker;
|
||||
@@ -53,7 +53,7 @@ public class IrisEngineSVC implements IrisService {
|
||||
long now = System.currentTimeMillis();
|
||||
lastUseLock.lock();
|
||||
try {
|
||||
for (Engine key : new ArrayList<>(lastUse.keySet())) {
|
||||
for (World key : new ArrayList<>(lastUse.keySet())) {
|
||||
Long last = lastUse.get(key);
|
||||
if (last == null)
|
||||
continue;
|
||||
@@ -100,7 +100,7 @@ public class IrisEngineSVC implements IrisService {
|
||||
Engine engine = supplier.get();
|
||||
if (engine != null) {
|
||||
long unloadStart = System.currentTimeMillis();
|
||||
int count = engine.getMantle().unloadTectonicPlate();
|
||||
int count = engine.getMantle().unloadTectonicPlate(tectonicLimit.get() / lastUse.size());
|
||||
if (count > 0) {
|
||||
Iris.debug(C.GOLD + "Unloaded " + C.YELLOW + count + " TectonicPlates in " + C.RED + Form.duration(System.currentTimeMillis() - unloadStart, 2));
|
||||
}
|
||||
@@ -128,7 +128,8 @@ public class IrisEngineSVC implements IrisService {
|
||||
}
|
||||
try {
|
||||
for (int j = 0; j < worlds.size(); j++) {
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(worlds.get(i.getAndIncrement()));
|
||||
World world = worlds.get(i.getAndIncrement());
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(world);
|
||||
if (i.get() >= worlds.size()) {
|
||||
i.set(0);
|
||||
}
|
||||
@@ -137,7 +138,7 @@ public class IrisEngineSVC implements IrisService {
|
||||
Engine engine = generator.getEngine();
|
||||
if (engine != null) {
|
||||
lastUseLock.lock();
|
||||
lastUse.put(engine, System.currentTimeMillis());
|
||||
lastUse.put(world, System.currentTimeMillis());
|
||||
lastUseLock.unlock();
|
||||
return engine;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,8 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
default void trim(int limit) {
|
||||
getMantle().trim(TimeUnit.SECONDS.toMillis(IrisSettings.get().getPerformance().getMantleKeepAlive()), limit);
|
||||
}
|
||||
default int unloadTectonicPlate(){
|
||||
return getMantle().unloadTectonicPlate();
|
||||
default int unloadTectonicPlate(int tectonicLimit){
|
||||
return getMantle().unloadTectonicPlate(tectonicLimit);
|
||||
}
|
||||
|
||||
default MultiBurst burst() {
|
||||
|
||||
@@ -444,15 +444,15 @@ public class Mantle {
|
||||
}
|
||||
}
|
||||
|
||||
public int unloadTectonicPlate() {
|
||||
public int unloadTectonicPlate(int tectonicLimit) {
|
||||
// todo: Make it advanced with bursts etc
|
||||
AtomicInteger i = new AtomicInteger();
|
||||
unloadLock.lock();
|
||||
try {
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
ExecutorService service = Executors.newFixedThreadPool(dynamicThreads.get());
|
||||
BurstExecutor burst = MultiBurst.burst.burst(toUnload.size());
|
||||
burst.setMulticore(toUnload.size() > tectonicLimit);
|
||||
for (long id : new ArrayList<>(toUnload)) {
|
||||
futures.add(service.submit(() ->
|
||||
burst.queue(() ->
|
||||
hyperLock.withLong(id, () -> {
|
||||
TectonicPlate m = loadedRegions.get(id);
|
||||
if (m != null) {
|
||||
@@ -467,16 +467,10 @@ public class Mantle {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})));
|
||||
}));
|
||||
}
|
||||
|
||||
try {
|
||||
while (!futures.isEmpty()) {
|
||||
futures.remove(0).get();
|
||||
futures.removeIf(Future::isDone);
|
||||
}
|
||||
service.shutdown();
|
||||
} catch (InterruptedException ignored) {}
|
||||
burst.complete();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user