Adds performance tweaking settings to config.yml

https://github.com/BentoBoxWorld/Level/issues/122
This commit is contained in:
tastybento 2020-01-16 13:44:23 -08:00
parent ccc3ef65be
commit fe0f084781
3 changed files with 69 additions and 10 deletions

View File

@ -1,6 +1,15 @@
package world.bentobox.level.calculators; package world.bentobox.level.calculators;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -92,17 +101,15 @@ public class CalcIslandLevel {
total += chunksToScan.size(); total += chunksToScan.size();
} }
} }
queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), new Runnable() { queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), () -> {
public void run() { for (int i = 0; i < addon.getSettings().getChunks(); i++) {
for (int i = 0; i < 10; i++) { if (q.size() == 0) {
if (q.size() == 0) { return;
return;
}
Chunk c = q.remove();
getChunk(c);
} }
Chunk c = q.remove();
getChunk(c);
} }
}, 1L, 1L); }, addon.getSettings().getTickDelay(), addon.getSettings().getTickDelay());
chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::addChunkQueue))); chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::addChunkQueue)));
} }

View File

@ -23,6 +23,8 @@ public class Settings {
private int deathpenalty; private int deathpenalty;
private long levelCost; private long levelCost;
private int levelWait; private int levelWait;
private int chunks;
private long taskDelay;
private List<String> gameModes; private List<String> gameModes;
@ -34,8 +36,21 @@ public class Settings {
// GameModes // GameModes
gameModes = level.getConfig().getStringList("game-modes"); gameModes = level.getConfig().getStringList("game-modes");
// Performance
setTickDelay(level.getConfig().getLong("task-delay",1));
if (taskDelay < 1L) {
level.logError("task-delay must be at least 1");
setTickDelay(1L);
}
setChunks(level.getConfig().getInt("chunks", 10));
if (chunks < 1) {
level.logError("chunks must be at least 1");
setChunks(1);
}
setLevelWait(level.getConfig().getInt("levelwait", 60)); setLevelWait(level.getConfig().getInt("levelwait", 60));
if (getLevelWait() < 0) { if (getLevelWait() < 0) {
level.logError("levelwait must be at least 0");
setLevelWait(0); setLevelWait(0);
} }
setDeathpenalty(level.getConfig().getInt("deathpenalty", 0)); setDeathpenalty(level.getConfig().getInt("deathpenalty", 0));
@ -228,4 +243,32 @@ public class Settings {
return level.getConfig().getString("level-calc", "blocks / level_cost"); return level.getConfig().getString("level-calc", "blocks / level_cost");
} }
/**
* @return the chunks
*/
public int getChunks() {
return chunks;
}
/**
* @param chunks the chunks to set
*/
public void setChunks(int chunks) {
this.chunks = chunks;
}
/**
* @return the tickDelay
*/
public long getTickDelay() {
return taskDelay;
}
/**
* @param tickDelay the tickDelay to set
*/
public void setTickDelay(long tickDelay) {
this.taskDelay = tickDelay;
}
} }

View File

@ -9,6 +9,15 @@ game-modes:
- CaveBlock - CaveBlock
#- SkyGrid #- SkyGrid
# Performance settings
# Level is very processor intensive, so these settings may need to be tweaked to optimize for your server
# Delay between each task that loads chunks for calulcating levels
# Increasing this will slow down level calculations but reduce average load
task-delay: 1
# Number of chunks that will be processed per task
chunks: 10
# This file lists the values for various blocks that are used to calculate the # This file lists the values for various blocks that are used to calculate the
# island level. Level = total of all blocks in island boundary / 100. # island level. Level = total of all blocks in island boundary / 100.
# Players with the permission askyblock.island.multiplier.# will have their blocks # Players with the permission askyblock.island.multiplier.# will have their blocks