Configurable lighting threads

This commit is contained in:
Sotr
2018-06-11 14:38:43 +08:00
parent c43b8592c9
commit b4da072470
3 changed files with 17 additions and 7 deletions

View File

@@ -184,6 +184,16 @@ public class AkarinGlobalConfig {
keepAliveTimeout = getSeconds(getString("core.keep-alive-response-timeout", "30s"));
}
public static int asyncLightingThreads;
private static void asyncLightingThreads() {
asyncLightingThreads = getInt("core.async-lighting.executor-threads", 2);
}
public static boolean asyncLightingWorkStealing;
private static void asyncLightingWorkStealing() {
asyncLightingWorkStealing = getBoolean("core.async-lighting.use-work-stealing", false);
}
public static boolean allowSpawnerModify;
private static void allowSpawnerModify() {
allowSpawnerModify = getBoolean("alternative.allow-spawner-modify", true);

View File

@@ -203,7 +203,7 @@ public abstract class MixinChunk implements IMixinChunk {
}
}
// this.m = false; // PAIL: isGapLightingUpdated
// this.isGapLightingUpdated = false;
}
}
@@ -250,11 +250,11 @@ public abstract class MixinChunk implements IMixinChunk {
this.lightExecutorService.execute(() -> {
this.checkLightAsync(neighborChunks);
});
} catch (RejectedExecutionException e) {
} catch (RejectedExecutionException ex) {
// This could happen if ServerHangWatchdog kills the server
// between the start of the method and the execute() call.
if (!this.world.getMinecraftServer().isStopped() && !this.lightExecutorService.isShutdown()) {
throw e;
throw ex;
}
}
} else {

View File

@@ -27,7 +27,6 @@ package io.akarin.server.mixin.lighting;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
@@ -36,6 +35,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.akarin.api.mixin.IMixinChunk;
import io.akarin.api.mixin.IMixinWorldServer;
import io.akarin.server.core.AkarinGlobalConfig;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.Chunk;
import net.minecraft.server.EnumDirection;
@@ -53,7 +53,8 @@ public abstract class MixinWorldServer extends MixinWorld implements IMixinWorld
private static final short XZ_MASK = 0xF;
private static final short Y_SHORT_MASK = 0xFF;
private final ExecutorService lightExecutorService = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setNameFormat("Akarin Async Light Thread").build());
private final ExecutorService lightExecutorService = AkarinGlobalConfig.asyncLightingWorkStealing ?
Executors.newFixedThreadPool(AkarinGlobalConfig.asyncLightingThreads, new ThreadFactoryBuilder().setNameFormat("Akarin Async Light Thread").build()) : Executors.newWorkStealingPool(AkarinGlobalConfig.asyncLightingThreads);
@Override
public boolean checkLightFor(EnumSkyBlock lightType, BlockPosition pos) { // PAIL: checkLightFor
@@ -239,7 +240,6 @@ public abstract class MixinWorldServer extends MixinWorld implements IMixinWorld
neighbor.setLightUpdateTime(chunk.getWorld().getTime());
}
//System.out.println("size = " + ((ThreadPoolExecutor) this.lightExecutorService).getQueue().size());
if (Bukkit.isPrimaryThread()) {
this.lightExecutorService.execute(() -> {
this.checkLightAsync(lightType, pos, chunk, neighbors);
@@ -342,7 +342,7 @@ public abstract class MixinWorldServer extends MixinWorld implements IMixinWorld
final Chunk chunk = this.getLightChunk(pos, currentChunk, neighbors);
if (chunk != null && !chunk.isUnloading()) {
chunk.a(type, pos, lightValue); // PAIL: setBrightness
this.notifyLightSet(pos); // PAIL: notifyLightSet
this.notifyLightSet(pos);
}
}
}