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