detect low tps
This commit is contained in:
@@ -6,7 +6,6 @@ package mc.core;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Slf4j
|
||||
@@ -17,10 +16,21 @@ public class GameLoop extends Thread {
|
||||
private long pause;
|
||||
@Setter
|
||||
private boolean traceTPS = false;
|
||||
private int lowTps;
|
||||
|
||||
public GameLoop() {
|
||||
super();
|
||||
setTps(20);
|
||||
setPercentWarnLowTps(5);
|
||||
}
|
||||
|
||||
public void setPercentWarnLowTps(int value) {
|
||||
if (value > 50) {
|
||||
log.warn("Percent warn low TPS can't be '{}'. Set 100", tps);
|
||||
value = 100;
|
||||
}
|
||||
|
||||
this.lowTps = tps - (int)(tps * (value / 100f));
|
||||
}
|
||||
|
||||
public void setTps(int tps) {
|
||||
@@ -34,28 +44,26 @@ public class GameLoop extends Thread {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int tpsFact = 0;
|
||||
log.info("Target TPS: {}; Low TPS: {}", tps, lowTps);
|
||||
int factTps = 0;
|
||||
long lastTime = System.currentTimeMillis();
|
||||
|
||||
while (!isInterrupted()) {
|
||||
if ((System.currentTimeMillis() - lastTime) > 1000) {
|
||||
lastTime = System.currentTimeMillis();
|
||||
if (traceTPS) {
|
||||
String msg = MessageFormatter.format("TPS: {}/{}", tpsFact, tps).getMessage();
|
||||
if (tpsFact < tps) {
|
||||
log.warn(msg);
|
||||
} else {
|
||||
log.info(msg);
|
||||
if (factTps < lowTps) {
|
||||
log.warn("Low TPS: {}/{}", factTps, tps);
|
||||
} else if (traceTPS) {
|
||||
log.info("TPS: {}/{}", factTps, tps);
|
||||
}
|
||||
}
|
||||
tpsFact = 0;
|
||||
factTps = 0;
|
||||
}
|
||||
|
||||
long futureTime = System.currentTimeMillis() + pause;
|
||||
|
||||
// code there //
|
||||
|
||||
tpsFact++;
|
||||
factTps++;
|
||||
try {
|
||||
Thread.sleep(futureTime - System.currentTimeMillis());
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user