mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-25 12:25:15 +01:00
Tweak thread pools thread counts, separate required linking thread pool
This commit is contained in:
parent
2f83770591
commit
d4f41c589d
@ -90,13 +90,13 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
return module;
|
||||
}
|
||||
|
||||
private CompletableFuture<Component> getBlockReason(UUID playerUUID) {
|
||||
private CompletableFuture<Component> getBlockReason(UUID playerUUID, String playerName) {
|
||||
BukkitRequiredLinkingModule module = getModule();
|
||||
if (module == null) {
|
||||
return CompletableFuture.completedFuture(Component.text("Discord unavailable, please try again later"));
|
||||
}
|
||||
|
||||
return module.getBlockReason(playerUUID);
|
||||
return module.getBlockReason(playerUUID, playerName);
|
||||
}
|
||||
|
||||
//
|
||||
@ -108,16 +108,19 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
"AsyncPlayerPreLoginEvent",
|
||||
priority,
|
||||
event.getUniqueId(),
|
||||
event.getName(),
|
||||
() -> event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED ? event.getLoginResult().name() : null,
|
||||
text -> event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, text)
|
||||
);
|
||||
}
|
||||
|
||||
private void handle(PlayerLoginEvent event, EventPriority priority) {
|
||||
Player player = event.getPlayer();
|
||||
handle(
|
||||
"PlayerLoginEvent",
|
||||
priority,
|
||||
event.getPlayer().getUniqueId(),
|
||||
player.getUniqueId(),
|
||||
player.getName(),
|
||||
() -> event.getResult() != PlayerLoginEvent.Result.ALLOWED ? event.getResult().name() : null,
|
||||
text -> event.disallow(PlayerLoginEvent.Result.KICK_OTHER, text)
|
||||
);
|
||||
@ -127,6 +130,7 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
String eventType,
|
||||
EventPriority priority,
|
||||
UUID playerUUID,
|
||||
String playerName,
|
||||
Supplier<String> alreadyBlocked,
|
||||
Consumer<String> disallow
|
||||
) {
|
||||
@ -138,11 +142,11 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
|
||||
String blockType = alreadyBlocked.get();
|
||||
if (blockType != null) {
|
||||
discordSRV.logger().debug(playerUUID + " is already blocked for " + eventType + "/" + priority + " (" + blockType + ")");
|
||||
discordSRV.logger().debug(playerName + " is already blocked for " + eventType + "/" + priority + " (" + blockType + ")");
|
||||
return;
|
||||
}
|
||||
|
||||
Component kickReason = getBlockReason(playerUUID).join();
|
||||
Component kickReason = getBlockReason(playerUUID, playerName).join();
|
||||
if (kickReason != null) {
|
||||
disallow.accept(BukkitComponentSerializer.legacy().serialize(kickReason));
|
||||
}
|
||||
@ -179,7 +183,7 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Component blockReason = getBlockReason(event.getUniqueId()).join();
|
||||
Component blockReason = getBlockReason(event.getUniqueId(), event.getName()).join();
|
||||
if (blockReason != null) {
|
||||
frozen.put(event.getUniqueId(), blockReason);
|
||||
}
|
||||
@ -267,7 +271,7 @@ public class BukkitRequiredLinkingListener implements Listener {
|
||||
player.sendMessage(Component.text("Checking..."));
|
||||
|
||||
UUID uuid = player.uniqueId();
|
||||
getBlockReason(uuid).whenComplete((reason, t) -> {
|
||||
getBlockReason(uuid, player.username()).whenComplete((reason, t) -> {
|
||||
if (t != null) {
|
||||
return;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.discordsrv.bukkit.requiredlinking;
|
||||
|
||||
import com.discordsrv.bukkit.BukkitDiscordSRV;
|
||||
import com.discordsrv.bukkit.config.main.BukkitRequiredLinkingConfig;
|
||||
import com.discordsrv.common.config.main.linking.RequirementsConfig;
|
||||
import com.discordsrv.common.linking.requirelinking.ServerRequireLinkingModule;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -30,7 +31,7 @@ public class BukkitRequiredLinkingModule extends ServerRequireLinkingModule<Bukk
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementsConfig config() {
|
||||
return discordSRV.config().requiredLinking.requirements;
|
||||
public BukkitRequiredLinkingConfig config() {
|
||||
return discordSRV.config().requiredLinking;
|
||||
}
|
||||
}
|
||||
|
@ -19,25 +19,60 @@
|
||||
package com.discordsrv.common.linking.requirelinking;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.config.main.linking.RequiredLinkingConfig;
|
||||
import com.discordsrv.common.linking.impl.MinecraftAuthenticationLinker;
|
||||
import com.discordsrv.common.linking.requirelinking.requirement.*;
|
||||
import com.discordsrv.common.linking.requirelinking.requirement.parser.RequirementParser;
|
||||
import com.discordsrv.common.module.type.AbstractModule;
|
||||
import com.discordsrv.common.scheduler.Scheduler;
|
||||
import com.discordsrv.common.scheduler.threadfactory.CountingThreadFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public abstract class RequiredLinkingModule<T extends DiscordSRV> extends AbstractModule<T> {
|
||||
|
||||
private final List<Requirement<?>> availableRequirements = new ArrayList<>();
|
||||
private ThreadPoolExecutor executor;
|
||||
|
||||
public RequiredLinkingModule(T discordSRV) {
|
||||
super(discordSRV);
|
||||
}
|
||||
|
||||
public abstract RequiredLinkingConfig config();
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return config().enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
executor = new ThreadPoolExecutor(
|
||||
1,
|
||||
Math.max(2, Runtime.getRuntime().availableProcessors() / 2),
|
||||
10,
|
||||
TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(),
|
||||
new CountingThreadFactory(Scheduler.THREAD_NAME_PREFIX + "RequiredLinking #%s")
|
||||
);
|
||||
|
||||
super.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (executor != null) {
|
||||
executor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadNoResult() {
|
||||
List<Requirement<?>> requirements = new ArrayList<>();
|
||||
|
@ -20,6 +20,7 @@ package com.discordsrv.common.linking.requirelinking;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.config.main.linking.RequirementsConfig;
|
||||
import com.discordsrv.common.config.main.linking.ServerRequiredLinkingConfig;
|
||||
import com.discordsrv.common.future.util.CompletableFutureUtil;
|
||||
import com.discordsrv.common.linking.LinkProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -38,7 +39,8 @@ public abstract class ServerRequireLinkingModule<T extends DiscordSRV> extends R
|
||||
super(discordSRV);
|
||||
}
|
||||
|
||||
public abstract RequirementsConfig config();
|
||||
@Override
|
||||
public abstract ServerRequiredLinkingConfig config();
|
||||
|
||||
@Override
|
||||
public void reloadNoResult() {
|
||||
@ -46,14 +48,15 @@ public abstract class ServerRequireLinkingModule<T extends DiscordSRV> extends R
|
||||
|
||||
synchronized (compiledRequirements) {
|
||||
compiledRequirements.clear();
|
||||
compiledRequirements.addAll(compile(config().requirements));
|
||||
compiledRequirements.addAll(compile(config().requirements.requirements));
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<Component> getBlockReason(UUID playerUUID) {
|
||||
RequirementsConfig config = config();
|
||||
public CompletableFuture<Component> getBlockReason(UUID playerUUID, String playerName) {
|
||||
RequirementsConfig config = config().requirements;
|
||||
if (config.bypassUUIDs.contains(playerUUID.toString())) {
|
||||
// Bypasses: let them through
|
||||
logger().debug("Player " + playerName + " is bypassing required linking requirements");
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@ -93,7 +96,7 @@ public abstract class ServerRequireLinkingModule<T extends DiscordSRV> extends R
|
||||
pass.complete(null);
|
||||
}
|
||||
}).exceptionally(t -> {
|
||||
logger().debug("Check \"" + requirement.input() + "\" failed for " + playerUUID + " / " + Long.toUnsignedString(userId), t);
|
||||
logger().debug("Check \"" + requirement.input() + "\" failed for " + playerName + " / " + Long.toUnsignedString(userId), t);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
@ -40,14 +40,17 @@ public class StandardScheduler implements Scheduler {
|
||||
this(
|
||||
discordSRV,
|
||||
new ThreadPoolExecutor(
|
||||
1, /* Core pool size */
|
||||
20, /* Max pool size */
|
||||
60, TimeUnit.SECONDS, /* Timeout */
|
||||
/* Core pool size */
|
||||
1,
|
||||
/* Max pool size: cpu cores / 2 or at least 1 */
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() / 2),
|
||||
/* Timeout */
|
||||
60, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(),
|
||||
new CountingThreadFactory(Scheduler.THREAD_NAME_PREFIX + "Executor #%s")
|
||||
),
|
||||
new ScheduledThreadPoolExecutor(
|
||||
0, /* Core pool size */
|
||||
1, /* Core pool size */
|
||||
new CountingThreadFactory(Scheduler.THREAD_NAME_PREFIX + "Scheduled Executor #%s")
|
||||
),
|
||||
new ForkJoinPool(
|
||||
@ -55,12 +58,12 @@ public class StandardScheduler implements Scheduler {
|
||||
Math.min(
|
||||
/* max of 10 */
|
||||
10,
|
||||
/* cpu cores - 1 or at least 1 */
|
||||
/* cpu cores / 2 or at least 1 */
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() - 1)
|
||||
),
|
||||
new CountingForkJoinWorkerThreadFactory(Scheduler.THREAD_NAME_PREFIX + "ForkJoinPool Worker #%s"),
|
||||
null,
|
||||
false /* FIFO */
|
||||
false /* async mode -> FIFO */
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user