2021-08-26 04:16:27 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 8 Aug 2021 16:26:46 -0700
Subject: [PATCH] Do not submit profile lookups to worldgen threads
They block. On network I/O.
If enough tasks are submitted the server will eventually stall
out due to a sync load, as the worldgen threads will be
stalling on profile lookups.
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
2023-12-05 22:34:01 +01:00
index 114f4017c4133042178c57d424f10079163835dd..aa52b271bd556a29f774fde375b713d0d187521b 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
2023-12-05 22:34:01 +01:00
@@ -89,6 +89,22 @@ public class Util {
2022-07-03 23:55:56 +02:00
private static final ExecutorService BACKGROUND_EXECUTOR = makeExecutor("Main");
2023-12-05 22:34:01 +01:00
private static final ExecutorService IO_POOL = makeIoExecutor("IO-Worker-", false);
private static final ExecutorService DOWNLOAD_POOL = makeIoExecutor("Download-", true);
2021-08-26 04:16:27 +02:00
+ // Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
+ public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
+
+ private final AtomicInteger count = new AtomicInteger();
+
+ @Override
+ public Thread newThread(Runnable run) {
+ Thread ret = new Thread(run);
+ ret.setName("Profile Lookup Executor #" + this.count.getAndIncrement());
+ ret.setUncaughtExceptionHandler((Thread thread, Throwable throwable) -> {
2022-02-28 23:02:20 +01:00
+ LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable);
2021-08-26 04:16:27 +02:00
+ });
+ return ret;
+ }
+ });
+ // Paper end - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
2022-07-27 21:49:24 +02:00
private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
2023-12-05 22:34:01 +01:00
private static final int LINEAR_LOOKUP_THRESHOLD = 8;
2023-09-21 22:35:39 +02:00
public static final long NANOS_PER_MILLI = 1000000L;
2021-08-26 04:16:27 +02:00
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2023-12-05 22:34:01 +01:00
index 68f95f4782c1effdee13543b702fdcc78ce14353..fdf3194499512614355b02aa11e34574cdd89c59 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2023-12-05 22:34:01 +01:00
@@ -170,7 +170,7 @@ public class GameProfileCache {
2021-08-26 04:16:27 +02:00
} else {
2023-09-21 22:35:39 +02:00
CompletableFuture<Optional<GameProfile>> completablefuture1 = CompletableFuture.supplyAsync(() -> {
2021-08-26 04:16:27 +02:00
return this.get(username);
- }, Util.backgroundExecutor()).whenCompleteAsync((optional, throwable) -> {
+ }, Util.PROFILE_EXECUTOR).whenCompleteAsync((optional, throwable) -> { // Paper - not a good idea to use BLOCKING OPERATIONS on the worldgen executor
this.requests.remove(username);
2023-09-21 22:35:39 +02:00
}, this.executor);
2021-08-26 04:16:27 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2023-12-05 22:34:01 +01:00
index bffc770105800ba78c6d9bfb56ad9ad425f19910..92b770d10f34596ce52392a0db1ccd825108730b 100644
2021-08-26 04:16:27 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2023-12-05 22:34:01 +01:00
@@ -80,7 +80,7 @@ public class SkullBlockEntity extends BlockEntity {
2023-09-21 22:35:39 +02:00
} else {
return Optional.empty();
}
- }, Util.backgroundExecutor());
+ }, Util.PROFILE_EXECUTOR); // Paper - not a good idea to use BLOCKING OPERATIONS on the worldgen executor
}
2023-12-05 22:34:01 +01:00
@Override
2022-07-03 23:55:56 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
2023-12-05 22:34:01 +01:00
index 358af0121ce3d87a9f51da2bae0699034c1560b4..91e913f8652584ffab44c44d10c0e0c47707e261 100644
2022-07-03 23:55:56 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
+++ b/src/main/java/org/bukkit/craftbukkit/profile/CraftPlayerProfile.java
2023-12-05 22:34:01 +01:00
@@ -122,7 +122,7 @@ public final class CraftPlayerProfile implements PlayerProfile {
2022-07-03 23:55:56 +02:00
@Override
public CompletableFuture<PlayerProfile> update() {
- return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.backgroundExecutor());
+ return CompletableFuture.supplyAsync(this::getUpdatedProfile, Util.PROFILE_EXECUTOR); // Paper - not a good idea to use BLOCKING OPERATIONS on the worldgen executor
}
private CraftPlayerProfile getUpdatedProfile() {