mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
isolate io stuff in its own MultiBurst
This commit is contained in:
@@ -485,6 +485,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
|||||||
.forEach(PlatformChunkGenerator::close);
|
.forEach(PlatformChunkGenerator::close);
|
||||||
|
|
||||||
MultiBurst.burst.close();
|
MultiBurst.burst.close();
|
||||||
|
MultiBurst.ioBurst.close();
|
||||||
services.clear();
|
services.clear();
|
||||||
});
|
});
|
||||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
||||||
|
|||||||
@@ -49,11 +49,10 @@ public class IrisSettings {
|
|||||||
private IrisSettingsSentry sentry = new IrisSettingsSentry();
|
private IrisSettingsSentry sentry = new IrisSettingsSentry();
|
||||||
|
|
||||||
public static int getThreadCount(int c) {
|
public static int getThreadCount(int c) {
|
||||||
return switch (c) {
|
return Math.max(switch (c) {
|
||||||
case -1, -2, -4 -> Runtime.getRuntime().availableProcessors() / -c;
|
case -1, -2, -4 -> Runtime.getRuntime().availableProcessors() / -c;
|
||||||
case 0, 1, 2 -> 1;
|
|
||||||
default -> Math.max(c, 2);
|
default -> Math.max(c, 2);
|
||||||
};
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IrisSettings get() {
|
public static IrisSettings get() {
|
||||||
@@ -138,6 +137,7 @@ public class IrisSettings {
|
|||||||
@Data
|
@Data
|
||||||
public static class IrisSettingsConcurrency {
|
public static class IrisSettingsConcurrency {
|
||||||
public int parallelism = -1;
|
public int parallelism = -1;
|
||||||
|
public int ioParallelism = -2;
|
||||||
public int worldGenParallelism = -1;
|
public int worldGenParallelism = -1;
|
||||||
|
|
||||||
public int getWorldGenThreads() {
|
public int getWorldGenThreads() {
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void savePrefetch(Engine engine) {
|
public void savePrefetch(Engine engine) {
|
||||||
BurstExecutor b = MultiBurst.burst.burst(loaders.size());
|
BurstExecutor b = MultiBurst.ioBurst.burst(loaders.size());
|
||||||
|
|
||||||
for (ResourceLoader<?> i : loaders.values()) {
|
for (ResourceLoader<?> i : loaders.values()) {
|
||||||
b.queue(() -> {
|
b.queue(() -> {
|
||||||
@@ -499,7 +499,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadPrefetch(Engine engine) {
|
public void loadPrefetch(Engine engine) {
|
||||||
BurstExecutor b = MultiBurst.burst.burst(loaders.size());
|
BurstExecutor b = MultiBurst.ioBurst.burst(loaders.size());
|
||||||
|
|
||||||
for (ResourceLoader<?> i : loaders.values()) {
|
for (ResourceLoader<?> i : loaders.values()) {
|
||||||
b.queue(() -> {
|
b.queue(() -> {
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
|||||||
|
|
||||||
public KList<T> loadAllParallel(KList<String> s) {
|
public KList<T> loadAllParallel(KList<String> s) {
|
||||||
KList<T> m = new KList<>();
|
KList<T> m = new KList<>();
|
||||||
BurstExecutor burst = MultiBurst.burst.burst(s.size());
|
BurstExecutor burst = MultiBurst.ioBurst.burst(s.size());
|
||||||
|
|
||||||
for (String i : s) {
|
for (String i : s) {
|
||||||
burst.queue(() -> {
|
burst.queue(() -> {
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ public class PreservationSVC implements IrisService {
|
|||||||
threads.add(t);
|
threads.add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(MultiBurst burst) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(ExecutorService service) {
|
public void register(ExecutorService service) {
|
||||||
services.add(service);
|
services.add(service);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class Mantle {
|
|||||||
this.ioTectonicUnload = new Semaphore(LOCK_SIZE, true);
|
this.ioTectonicUnload = new Semaphore(LOCK_SIZE, true);
|
||||||
loadedRegions = new KMap<>();
|
loadedRegions = new KMap<>();
|
||||||
lastUse = new KMap<>();
|
lastUse = new KMap<>();
|
||||||
ioBurst = MultiBurst.burst;
|
ioBurst = MultiBurst.ioBurst;
|
||||||
adjustedIdleDuration = new AtomicDouble(0);
|
adjustedIdleDuration = new AtomicDouble(0);
|
||||||
toUnload = new KSet<>();
|
toUnload = new KSet<>();
|
||||||
worker = new IOWorker(dataFolder, worldHeight);
|
worker = new IOWorker(dataFolder, worldHeight);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package com.volmit.iris.util.parallel;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
import com.volmit.iris.core.service.PreservationSVC;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
@@ -30,30 +29,37 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.function.IntSupplier;
|
||||||
|
|
||||||
public class MultiBurst implements ExecutorService {
|
public class MultiBurst implements ExecutorService {
|
||||||
private static final long TIMEOUT = Long.getLong("iris.burst.timeout", 15000);
|
private static final long TIMEOUT = Long.getLong("iris.burst.timeout", 15000);
|
||||||
public static final MultiBurst burst = new MultiBurst();
|
public static final MultiBurst burst = new MultiBurst();
|
||||||
|
public static final MultiBurst ioBurst = new MultiBurst("Iris IO", () -> IrisSettings.get().getConcurrency().getIoParallelism());
|
||||||
private final AtomicLong last;
|
private final AtomicLong last;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int priority;
|
private final int priority;
|
||||||
|
private final IntSupplier parallelism;
|
||||||
private ExecutorService service;
|
private ExecutorService service;
|
||||||
|
|
||||||
public MultiBurst() {
|
public MultiBurst() {
|
||||||
this("Iris", Thread.MIN_PRIORITY);
|
this("Iris", Thread.MIN_PRIORITY, () -> IrisSettings.get().getConcurrency().getParallelism());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiBurst(String name, int priority) {
|
public MultiBurst(String name, IntSupplier parallelism) {
|
||||||
|
this(name, Thread.MIN_PRIORITY, parallelism);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiBurst(String name, int priority, IntSupplier parallelism) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
|
this.parallelism = parallelism;
|
||||||
last = new AtomicLong(M.ms());
|
last = new AtomicLong(M.ms());
|
||||||
Iris.service(PreservationSVC.class).register(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ExecutorService getService() {
|
private synchronized ExecutorService getService() {
|
||||||
last.set(M.ms());
|
last.set(M.ms());
|
||||||
if (service == null || service.isShutdown()) {
|
if (service == null || service.isShutdown()) {
|
||||||
service = new ForkJoinPool(IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism()),
|
service = new ForkJoinPool(IrisSettings.getThreadCount(parallelism.getAsInt()),
|
||||||
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
||||||
int m = 0;
|
int m = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user