Incremental Auto Save Players

Take same approach we did for chunks, and only save player if its been X time since last save,
instead of doing it all in 1 tick.

This is even more helpful considering Player Saving is done sync for File IO.
This commit is contained in:
Aikar 2016-12-27 16:11:25 -05:00
parent bf756994b0
commit d231cef8cd
5 changed files with 100 additions and 30 deletions

View File

@ -1,4 +1,4 @@
From dd5d1ed559dd433fe9651af7c83591e1a9b08efd Mon Sep 17 00:00:00 2001
From a57aee2b24023bd4c1e0c17e153cc87832faf7b2 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 19 Sep 2016 23:16:39 -0400
Subject: [PATCH] Auto Save Improvements
@ -9,8 +9,24 @@ Process auto save every tick instead of once per auto tick interval, so that chu
Re-introduce a cap per tick for auto save (Spigot disabled the vanilla cap) and make it configurable.
Adds incremental player auto saving too
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 3161dad45..668b375e1 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -241,4 +241,9 @@ public class PaperConfig {
flyingKickPlayerMessage = getString("messages.kick.flying-player", flyingKickPlayerMessage);
flyingKickVehicleMessage = getString("messages.kick.flying-vehicle", flyingKickVehicleMessage);
}
+
+ public static int playerAutoSaveRate = -1;
+ private static void playerAutoSaveRate() {
+ playerAutoSaveRate = getInt("settings.player-auto-save-rate", -1);
+ }
}
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 965edc9..da530f9 100644
index 965edc99c..da530f9aa 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -2,6 +2,7 @@ package com.destroystokyo.paper;
@ -42,7 +58,7 @@ index 965edc9..da530f9 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 88437d7..9f7f32d 100644
index 88437d77a..9f7f32dc2 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -960,11 +960,9 @@ public class Chunk {
@ -60,7 +76,7 @@ index 88437d7..9f7f32d 100644
public Random a(long i) {
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 7a56a64..5c5a56c 100644
index 7a56a6416..5c5a56c51 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -1,5 +1,6 @@
@ -79,8 +95,20 @@ index 7a56a64..5c5a56c 100644
return false;
}
}
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index de2d4394b..4ad336e38 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -29,6 +29,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
private static final Logger bR = LogManager.getLogger();
public String locale = null; // Spigot private -> public // Paper - default to null
+ public long lastSave = MinecraftServer.currentTick; // Paper
public PlayerConnection playerConnection;
public final MinecraftServer server;
public final PlayerInteractManager playerInteractManager;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 184cb72..b307b2b 100644
index 03185f789..85fd972bb 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -117,6 +117,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@ -91,16 +119,21 @@ index 184cb72..b307b2b 100644
// CraftBukkit end
public MinecraftServer(OptionSet options, Proxy proxy, DataConverterManager dataconvertermanager, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
@@ -760,22 +761,26 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
@@ -760,22 +761,30 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
this.q.b().a(agameprofile);
}
- if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
this.methodProfiler.a("save");
- this.v.savePlayers();
+
+ serverAutoSave = (autosavePeriod > 0 && this.ticks % autosavePeriod == 0); // Paper
+ if (serverAutoSave) { // CraftBukkit // Paper
this.v.savePlayers();
+ int playerSaveInterval = com.destroystokyo.paper.PaperConfig.playerAutoSaveRate;
+ if (playerSaveInterval < 0) {
+ playerSaveInterval = autosavePeriod;
+ }
+ if (playerSaveInterval > 0) { // CraftBukkit // Paper
+ this.v.savePlayers(playerSaveInterval);
// Spigot Start
+ } // Paper - Incremental Auto Saving
+
@ -121,8 +154,45 @@ index 184cb72..b307b2b 100644
this.methodProfiler.a("tallying");
this.h[this.ticks % 100] = System.nanoTime() - i;
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
index b14d4cb7f..2f527f6ce 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -330,6 +330,7 @@ public abstract class PlayerList {
}
protected void savePlayerFile(EntityPlayer entityplayer) {
+ entityplayer.lastSave = MinecraftServer.currentTick; // Paper
this.playerFileData.save(entityplayer);
ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.o.get(entityplayer.getUniqueID());
@@ -1205,13 +1206,23 @@ public abstract class PlayerList {
}
+ // Paper start
public void savePlayers() {
+ savePlayers(null);
+ }
+
+ public void savePlayers(Integer interval) {
+ long now = MinecraftServer.currentTick;
MinecraftTimings.savePlayers.startTiming(); // Paper
for (int i = 0; i < this.players.size(); ++i) {
- this.savePlayerFile((EntityPlayer) this.players.get(i));
+ EntityPlayer entityplayer = this.players.get(i);
+ if (interval == null || now - entityplayer.lastSave >= interval) {
+ this.savePlayerFile(entityplayer);
+ }
}
MinecraftTimings.savePlayers.stopTiming(); // Paper
}
+ // Paper end
public void addWhitelist(GameProfile gameprofile) {
this.whitelist.add(new WhiteListEntry(gameprofile));
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 5bf7df7..bfa87d7 100644
index 5bf7df7ee..bfa87d73d 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -1002,8 +1002,9 @@ public class WorldServer extends World implements IAsyncTaskHandler {
@ -145,5 +215,5 @@ index 5bf7df7..bfa87d7 100644
timings.worldSaveChunks.startTiming(); // Paper
chunkproviderserver.a(flag);
--
2.9.3
2.11.0

View File

@ -1,4 +1,4 @@
From e154ac33d32fa8d2f4d82281fcada3d6b738416d Mon Sep 17 00:00:00 2001
From 2e713ba23758c2e03a64f0239356407df62e730a Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 21 Sep 2016 23:48:39 -0400
Subject: [PATCH] Auto fix bad Y levels on player login
@ -6,10 +6,10 @@ Subject: [PATCH] Auto fix bad Y levels on player login
Bring down to a saner Y level if super high, as this can cause the server to crash
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index de2d439..00fca19 100644
index 4ad336e38..ab2b4c404 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -126,6 +126,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -127,6 +127,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
}
@ -18,5 +18,5 @@ index de2d439..00fca19 100644
}
--
2.9.3
2.11.0

View File

@ -1,11 +1,11 @@
From a6f36055caaf81e45853ce81401361fa9d4b4254 Mon Sep 17 00:00:00 2001
From 049172acbe149163c86945185f962ce662331cc2 Mon Sep 17 00:00:00 2001
From: Alfie Cleveland <alfeh@me.com>
Date: Fri, 25 Nov 2016 13:22:40 +0000
Subject: [PATCH] Optimise removeQueue
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 00fca19..523d916 100644
index ab2b4c404..fa09ef111 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -4,7 +4,9 @@ import com.google.common.collect.Lists;
@ -18,7 +18,7 @@ index 00fca19..523d916 100644
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -34,7 +36,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -35,7 +37,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
public final PlayerInteractManager playerInteractManager;
public double d;
public double e;
@ -27,7 +27,7 @@ index 00fca19..523d916 100644
private final ServerStatisticManager bU;
private float bV = Float.MIN_VALUE;
private int bW = Integer.MIN_VALUE;
@@ -246,10 +248,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -247,10 +249,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
Iterator iterator = this.removeQueue.iterator();
int j = 0;
@ -46,7 +46,7 @@ index 00fca19..523d916 100644
this.playerConnection.sendPacket(new PacketPlayOutEntityDestroy(aint));
}
@@ -986,7 +995,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -987,7 +996,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
this.lastSentExp = -1;
this.lastHealthSent = -1.0F;
this.cc = -1;
@ -61,5 +61,5 @@ index 00fca19..523d916 100644
protected void a(MobEffect mobeffect) {
--
2.9.3
2.11.0

View File

@ -1,16 +1,16 @@
From 40667ff98170c1e7b5ff68d32697433cf707c3f1 Mon Sep 17 00:00:00 2001
From eb8748d01fdae9225497d11a105d73565e577059 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Tue, 20 Dec 2016 23:09:21 -0600
Subject: [PATCH] Add option to remove invalid statistics
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
index 3161dad..9e6071e 100644
index 668b375e1..569a1a9ab 100644
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
@@ -241,4 +241,9 @@ public class PaperConfig {
flyingKickPlayerMessage = getString("messages.kick.flying-player", flyingKickPlayerMessage);
flyingKickVehicleMessage = getString("messages.kick.flying-vehicle", flyingKickVehicleMessage);
@@ -246,4 +246,9 @@ public class PaperConfig {
private static void playerAutoSaveRate() {
playerAutoSaveRate = getInt("settings.player-auto-save-rate", -1);
}
+
+ public static boolean removeInvalidStatistics = false;
@ -19,7 +19,7 @@ index 3161dad..9e6071e 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/ServerStatisticManager.java b/src/main/java/net/minecraft/server/ServerStatisticManager.java
index 99466db..d1bee02 100644
index 99466dbde..d1bee0257 100644
--- a/src/main/java/net/minecraft/server/ServerStatisticManager.java
+++ b/src/main/java/net/minecraft/server/ServerStatisticManager.java
@@ -104,6 +104,7 @@ public class ServerStatisticManager extends StatisticManager {
@ -49,5 +49,5 @@ index 99466db..d1bee02 100644
}
}
--
2.9.3
2.11.0

View File

@ -1,4 +1,4 @@
From b078c9b21409986a6ee694001bafa9baf17a7212 Mon Sep 17 00:00:00 2001
From 25b62826b3a8d49c0f3aa9fbc1b5e93d541288c4 Mon Sep 17 00:00:00 2001
From: Alfie Cleveland <alfeh@me.com>
Date: Tue, 27 Dec 2016 01:57:57 +0000
Subject: [PATCH] Properly fix item duplication bug
@ -6,10 +6,10 @@ Subject: [PATCH] Properly fix item duplication bug
Credit to prplz for figuring out the real issue
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 523d91675..60219f97c 100644
index fa09ef111..c70390463 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -1328,7 +1328,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -1329,7 +1329,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@Override
protected boolean isFrozen() {