Substantially reduce disk IO in mass destruction:
Previously, the signs config file was saved for every single change to its contents. This works great until you have an episode of mass destruction. Suddenly, you're getting the file saved multiple times per tick. Goodbye, TPS. Hello, lag. This commit replaces the functionality of the saveSigns method with flagging the signs config as requiring a save. A scheduled task checking for this boolean once per second allows for up-to-the-second accuracy of the config file without substantially compromising server stability. Lastly, the config is saved in onDisable to ensure the task hasn't missed anything.
This commit is contained in:
@@ -53,6 +53,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
private int inventoriesToDrop = 0;
|
private int inventoriesToDrop = 0;
|
||||||
private YamlConfiguration signs;
|
private YamlConfiguration signs;
|
||||||
private File signsFile;
|
private File signsFile;
|
||||||
|
private boolean saveQueued;
|
||||||
private String name = "";
|
private String name = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,6 +81,15 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
if (getConfig().getBoolean("cleanup.enable", false)) {
|
if (getConfig().getBoolean("cleanup.enable", false)) {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConfig().getInt("cleanup.lastEdit", 30)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (saveQueued) {
|
||||||
|
saveSignsFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(this, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startMetrics() {
|
private void startMetrics() {
|
||||||
@@ -118,6 +128,7 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
}
|
}
|
||||||
|
saveSignsFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkUpdate() {
|
protected void checkUpdate() {
|
||||||
@@ -193,6 +204,11 @@ public class PlayerVaults extends JavaPlugin {
|
|||||||
* Save the signs.yml file.
|
* Save the signs.yml file.
|
||||||
*/
|
*/
|
||||||
public void saveSigns() {
|
public void saveSigns() {
|
||||||
|
saveQueued = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveSignsFile() {
|
||||||
|
saveQueued = false;
|
||||||
try {
|
try {
|
||||||
signs.save(this.signsFile);
|
signs.save(this.signsFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user