Skip (most) lazy permission updating in case of heavy load. (+)

This doesn't account for lag, but keeps the impact down slightly. Not
sure this is really useful.

(+) Only run set back for online players. Quitting has to be handled
differently.
(+) Comments.
This commit is contained in:
asofold 2018-02-07 18:46:03 +01:00
parent 5d5e45e2df
commit eabd648ad7
3 changed files with 35 additions and 7 deletions

View File

@ -82,7 +82,6 @@ public class DefaultConfig extends ConfigFile {
"nocheatplus.notify :: INTERVAL:60, -world, -offline", // Not sure about this one.
"nocheatplus.admin.debug :: INTERVAL:5",
"nocheatplus.admin* :: ALWAYS",
// TODO: NOTIFY (not command).
// TODO: Command permissions are always checked anyway :p. Will be changed...
"nocheatplus.command* :: ALWAYS",
"nocheatplus.bypass* :: ALWAYS",

View File

@ -182,6 +182,11 @@ public class DataManager implements INeedConfig, ComponentRegistry<IRemoveData>,
};
private final MiniListener<?>[] miniListeners = new MiniListener<?>[] {
/*
* TODO: Constants in a class 'ListenerTags', plus a plan
* (system.data.player.nocheatplus, system.nocheatplus.data ??,
* nocheatplus.system.data.player...). (RegistryTags for other?).
*/
new MiniListener<PlayerQuitEvent>() {
@Override
@EventHandler(priority = EventPriority.MONITOR)

View File

@ -36,6 +36,7 @@ import fr.neatmonster.nocheatplus.permissions.PermissionPolicy.FetchingPolicy;
import fr.neatmonster.nocheatplus.permissions.PermissionRegistry;
import fr.neatmonster.nocheatplus.permissions.RegisteredPermission;
import fr.neatmonster.nocheatplus.utilities.ds.corw.DualSet;
import fr.neatmonster.nocheatplus.utilities.ds.count.ActionFrequency;
import fr.neatmonster.nocheatplus.utilities.ds.map.HashMapLOW;
/**
@ -82,7 +83,10 @@ public class PlayerData implements IData, ICanHandleTimeRunningBackwards {
* data-related.
*/
// TODO: Use the same lock for permissions stuff ?
/** Monitor player task load across all players (nanoseconds per server tick). */
private static ActionFrequency taskLoad = new ActionFrequency(6, 7);
/** Some measure for heavy load, for skipping some of the (lazy) updating. */
private static float heavyLoad = 1000000f; // 1 ms = 2 % of a tick.
// Default tags.
public static final String TAG_NOTIFY_OFF = "notify_off";
@ -94,6 +98,8 @@ public class PlayerData implements IData, ICanHandleTimeRunningBackwards {
// Instance //
//////////////
// TODO: Use the same lock for permissions stuff ?
/** Not sure this is the future of extra properties. */
private Set<String> tags = null;
@ -212,15 +218,19 @@ public class PlayerData implements IData, ICanHandleTimeRunningBackwards {
@SuppressWarnings("deprecation")
private void frequentTasks(final int tick, final long timeLast, final Player player) {
if (player != null) { // Common criteria ...
if (requestPlayerSetBack) {
requestPlayerSetBack = false;
MovingUtil.processStoredSetBack(player, "Player set back on tick: ");
}
if (player.isOnline()) {
long nanos = System.nanoTime();
// Set back.
if (requestPlayerSetBack) {
requestPlayerSetBack = false;
MovingUtil.processStoredSetBack(player, "Player set back on tick: ");
}
// Inventory update.
if (requestUpdateInventory) {
requestUpdateInventory = false;
player.updateInventory();
}
// Permission updates (high priority).
final Collection<RegisteredPermission> updatable = updatePermissions.getMergePrimaryThreadAndClear();
if (updatable != null) {
for (final RegisteredPermission registeredPermission : updatable) {
@ -228,9 +238,12 @@ public class PlayerData implements IData, ICanHandleTimeRunningBackwards {
hasPermission(registeredPermission, player);
}
}
nanos = System.nanoTime() - nanos;
if (nanos > 0L) {
taskLoad.add(tick, nanos);
}
} // (The player is online.)
} // (The player is not null.)
}
private boolean hasLazyTasks() {
@ -248,13 +261,24 @@ public class PlayerData implements IData, ICanHandleTimeRunningBackwards {
if (player == null) {
return true;
}
long nanos = System.nanoTime();
taskLoad.update(tick);
final boolean isHeavyLoad = taskLoad.score(1f) > heavyLoad;
updatePermissionsLazy.mergePrimaryThread();
final Iterator<RegisteredPermission> it = updatePermissionsLazy.iteratorPrimaryThread();
// TODO: Load balancing with other tasks ?
while (it.hasNext()) {
hasPermission(it.next(), player);
it.remove();
if (isHeavyLoad) {
break;
}
}
boolean hasWrk = it.hasNext();
nanos = System.nanoTime() - nanos;
if (nanos > 0L) {
taskLoad.add(tick, nanos);
}
return !hasWrk;
}