Archived
0

detect low tps

This commit is contained in:
2018-04-21 11:48:47 +03:00
parent 3b6d43443b
commit abfbfda926

View File

@@ -6,7 +6,6 @@ package mc.core;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@Slf4j @Slf4j
@@ -17,10 +16,21 @@ public class GameLoop extends Thread {
private long pause; private long pause;
@Setter @Setter
private boolean traceTPS = false; private boolean traceTPS = false;
private int lowTps;
public GameLoop() { public GameLoop() {
super(); super();
setTps(20); 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) { public void setTps(int tps) {
@@ -34,28 +44,26 @@ public class GameLoop extends Thread {
@Override @Override
public void run() { public void run() {
int tpsFact = 0; log.info("Target TPS: {}; Low TPS: {}", tps, lowTps);
int factTps = 0;
long lastTime = System.currentTimeMillis(); long lastTime = System.currentTimeMillis();
while (!isInterrupted()) { while (!isInterrupted()) {
if ((System.currentTimeMillis() - lastTime) > 1000) { if ((System.currentTimeMillis() - lastTime) > 1000) {
lastTime = System.currentTimeMillis(); lastTime = System.currentTimeMillis();
if (traceTPS) { if (factTps < lowTps) {
String msg = MessageFormatter.format("TPS: {}/{}", tpsFact, tps).getMessage(); log.warn("Low TPS: {}/{}", factTps, tps);
if (tpsFact < tps) { } else if (traceTPS) {
log.warn(msg); log.info("TPS: {}/{}", factTps, tps);
} else {
log.info(msg);
}
} }
tpsFact = 0; factTps = 0;
} }
long futureTime = System.currentTimeMillis() + pause; long futureTime = System.currentTimeMillis() + pause;
// code there // // code there //
tpsFact++; factTps++;
try { try {
Thread.sleep(futureTime - System.currentTimeMillis()); Thread.sleep(futureTime - System.currentTimeMillis());
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {