Skip to content

Commit

Permalink
Adds performance tweaking settings to config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 16, 2020
1 parent ccc3ef6 commit fe0f084
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
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.AtomicLong;

Expand Down Expand Up @@ -92,17 +101,15 @@ public CalcIslandLevel(final Level addon, final Island island, final Runnable on
total += chunksToScan.size();
}
}
queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), new Runnable() {
public void run() {
for (int i = 0; i < 10; i++) {
if (q.size() == 0) {
return;
}
Chunk c = q.remove();
getChunk(c);
queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), () -> {
for (int i = 0; i < addon.getSettings().getChunks(); i++) {
if (q.size() == 0) {
return;
}
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)));

}
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/world/bentobox/level/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Settings {
private int deathpenalty;
private long levelCost;
private int levelWait;
private int chunks;
private long taskDelay;

private List<String> gameModes;

Expand All @@ -33,9 +35,22 @@ public Settings(Level level) {

// GameModes
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));
if (getLevelWait() < 0) {
level.logError("levelwait must be at least 0");
setLevelWait(0);
}
setDeathpenalty(level.getConfig().getInt("deathpenalty", 0));
Expand Down Expand Up @@ -228,4 +243,32 @@ public String getLevelCalc() {
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;
}

}
9 changes: 9 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ game-modes:
- CaveBlock
#- 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
# island level. Level = total of all blocks in island boundary / 100.
# Players with the permission askyblock.island.multiplier.# will have their blocks
Expand Down

0 comments on commit fe0f084

Please sign in to comment.