Add QuitHooks and ServerMapQuitSleepPerformancePatch for Build 42.21. Optimize server shutdown by replacing fixed sleep with client connection polling. Include hooks, unit tests, and integrate the patch into the performance patch set.
This commit is contained in:
1 parent
99f4f49a7c
commit
e61026a3d4
5 files changed
+187
-11
No files matched your search
+2
-1
@@ -39,7 +39,8 @@ public final class B42PatchSet implements PatchSet
|
||||
new ServerPlayersVehiclesRoundPerformancePatch(),
|
||||
new ServerPlayersVehiclesStopPerformancePatch(),
|
||||
new ServerPlayerDBSaveWaitPerformancePatch(),
|
||||
new GameServerAssetLoadingPerformancePatch()
|
||||
new GameServerAssetLoadingPerformancePatch(),
|
||||
new ServerMapQuitSleepPerformancePatch()
|
||||
);
|
||||
|
||||
@Override
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package dev.overlord.zomboidforge.compat.b42.perf;
|
||||
|
||||
import dev.overlord.zomboidforge.api.GameVersion;
|
||||
import dev.overlord.zomboidforge.patcher.Anchor;
|
||||
import dev.overlord.zomboidforge.patcher.Hook;
|
||||
import dev.overlord.zomboidforge.patcher.patches.ThreadSleepPerformancePatch;
|
||||
|
||||
/**
|
||||
* {@code ServerMap.QueuedQuit()} sleeps 5 s after the world save and the {@code ServerQuit}
|
||||
* broadcast, so the clients can disconnect. The sleep becomes {@code QuitHooks.quitSleep}. With
|
||||
* the feature {@code experimental_performance} enabled, the shutdown continues as soon as no
|
||||
* client is connected, after at most 5s. With the feature disabled, it keeps the vanilla sleep.
|
||||
*/
|
||||
public final class ServerMapQuitSleepPerformancePatch extends ThreadSleepPerformancePatch
|
||||
{
|
||||
private static final Hook HOOK = new Hook("dev/overlord/zomboidforge/compat/b42/hooks/QuitHooks", "quitSleep", "(J)V");
|
||||
|
||||
public ServerMapQuitSleepPerformancePatch() {
|
||||
super("zombie/network/ServerMap", new Anchor.Method("QueuedQuit", "()V"), 1, ServerMapQuitSleepPerformancePatch.HOOK);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(GameVersion version) { return version.matches("42.21"); }
|
||||
}
|
||||
+11
-10
@@ -26,13 +26,13 @@ import static org.objectweb.asm.Opcodes.LCONST_1;
|
||||
import static org.objectweb.asm.Opcodes.RETURN;
|
||||
import static org.objectweb.asm.Opcodes.V25;
|
||||
|
||||
/** The five Build 42 waiting-loop patches: each with its target, number of sleeps and hook. */
|
||||
/** The Build 42 patches that redirect {@code Thread.sleep}: each with its target, number of sleeps and hook. */
|
||||
class ThreadSleepPatchesTest
|
||||
{
|
||||
private static final String HOOKS = "dev/overlord/zomboidforge/compat/b42/hooks/WaitHooks";
|
||||
private static final String HOOKS = "dev/overlord/zomboidforge/compat/b42/hooks/";
|
||||
|
||||
/** Each patch with its target method, number of sleeps and hook. */
|
||||
private record Case(ThreadSleepPerformancePatch patch, String target, String method, int sleeps, String hook)
|
||||
/** Each patch with its target method, number of sleeps, hook class and hook. */
|
||||
private record Case(ThreadSleepPerformancePatch patch, String target, String method, int sleeps, String hooks, String hook)
|
||||
{
|
||||
@Override
|
||||
public @NonNull String toString() { return this.patch.getClass().getSimpleName(); }
|
||||
@@ -41,11 +41,12 @@ class ThreadSleepPatchesTest
|
||||
private static Stream<Case> cases()
|
||||
{
|
||||
return Stream.of(
|
||||
new Case(new ServerChunkLoaderQuitPerformancePatch(), "zombie/network/ServerChunkLoader", "quit", 2, "pollSleep"),
|
||||
new Case(new ZipBackupWaitPerformancePatch(), "zombie/core/backup/ZipBackup", "waitFinish", 1, "pollSleep"),
|
||||
new Case(new ServerPlayersVehiclesRoundPerformancePatch(), "zombie/network/ServerPlayersVehicles$SPVThread", "runInner", 1, "vehicleRoundSleep"),
|
||||
new Case(new ServerPlayersVehiclesStopPerformancePatch(), "zombie/network/ServerPlayersVehicles", "stop", 1, "wakeVehiclesAndPoll"),
|
||||
new Case(new ServerPlayerDBSaveWaitPerformancePatch(), "zombie/savefile/ServerPlayerDB", "saveFinishWait", 1, "wakeVehiclesAndPoll")
|
||||
new Case(new ServerChunkLoaderQuitPerformancePatch(), "zombie/network/ServerChunkLoader", "quit", 2, "WaitHooks", "pollSleep"),
|
||||
new Case(new ZipBackupWaitPerformancePatch(), "zombie/core/backup/ZipBackup", "waitFinish", 1, "WaitHooks", "pollSleep"),
|
||||
new Case(new ServerPlayersVehiclesRoundPerformancePatch(), "zombie/network/ServerPlayersVehicles$SPVThread", "runInner", 1, "WaitHooks", "vehicleRoundSleep"),
|
||||
new Case(new ServerPlayersVehiclesStopPerformancePatch(), "zombie/network/ServerPlayersVehicles", "stop", 1, "WaitHooks", "wakeVehiclesAndPoll"),
|
||||
new Case(new ServerPlayerDBSaveWaitPerformancePatch(), "zombie/savefile/ServerPlayerDB", "saveFinishWait", 1, "WaitHooks", "wakeVehiclesAndPoll"),
|
||||
new Case(new ServerMapQuitSleepPerformancePatch(), "zombie/network/ServerMap", "QueuedQuit", 1, "QuitHooks", "quitSleep")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,7 +98,7 @@ class ThreadSleepPatchesTest
|
||||
for (MethodInsnNode call : calls)
|
||||
{
|
||||
assertEquals(INVOKESTATIC, call.getOpcode());
|
||||
assertEquals(ThreadSleepPatchesTest.HOOKS, call.owner);
|
||||
assertEquals(ThreadSleepPatchesTest.HOOKS + test.hooks(), call.owner);
|
||||
assertEquals(test.hook(), call.name);
|
||||
assertEquals("(J)V", call.desc);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user