Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spigot 1.12 - If NPC cannot reach target, it overloads server CPU performance and cost lags #179

Closed
GreenFlagCZ opened this issue Jul 15, 2017 · 8 comments

Comments

@GreenFlagCZ
Copy link

GreenFlagCZ commented Jul 15, 2017

Sever: Spigot 1.12 Build 201707090430
Plugin version: Sentinel 1.3.1

Hello, there is an issue. If NPC has not a clear path and cannot reach target (for example mob is on the tree), the CPU of the server start overloading (in my case up to 70% from normal condition) and its only ONE NPC. I dont know, what happens, if this issue will start with other NPCs on my server. It can cost big server lags.

example:
server start overloading: NPC [Straz] targeted the witch, but hasn't clear path and cant reach the witch, because mob staying on the stone wall
http://riftsite.cz/wp-content/uploads/2017/07/2-NPC-cannot-reach-target.jpg

server stop overloading: NPC [Straz] can again reach target, because has clear path to the witch ( I push the witch from wall)
http://riftsite.cz/wp-content/uploads/2017/07/3-NPC-reach-target-after-mob-is-in-path-range.jpg

Thank you for solving this
Best regards
Green

@mcmonkey4eva
Copy link
Member

Can you get a more careful analysis of this? There's a plugin somewhere that shows method-by-method weights of CPU stressors, which will help identify what went wrong here.

Quite possibly just a too big pathfinding range.

@GreenFlagCZ
Copy link
Author

GreenFlagCZ commented Aug 3, 2017

I ll try to analyse. I tryed reduce pathfinding and range/chaserange from default 25 to 10, but it's not a solution, it's only reduce the chance if that happend.

@GreenFlagCZ
Copy link
Author

GreenFlagCZ commented Aug 3, 2017

....
....
I create a 4 block tower near to him
Spawn monster on tower.

Also I find, if NPC is naturaly blocked, like he is in cage but see target, CPU will no overloads,
but if he hasnt any block and monster is on top of tower, it will overloads

NPC stats above like I described...
in cage:
http://riftsite.cz/wp-content/uploads/2017/08/1.jpg

NPC released
http://riftsite.cz/wp-content/uploads/2017/08/3.jpg
http://riftsite.cz/wp-content/uploads/2017/08/4.jpg

@GreenFlagCZ
Copy link
Author

GreenFlagCZ commented Aug 27, 2017

net.Citizensnpcs.api.astar.pathfinder.CachingChunkBlockSource.getBlockTypeIdAt(CachingChunkBlockSour ce.java:41) at net.Citizensnpcs.api.astar.pathfinder.BlockSource.getMaterialAt(BlockSource.java:11) at net.Citizensnpcs.api.astar.pathfinder.BlockSource.getMaterialAt(BlockSource.java:15) at net.Citizensnpcs.npc.ai.CitizensNavigator$DoorExaminer.isPassable(CitizensNavigator.java:394) at net.Citizensnpcs.api.astar.pathfinder.VectorNode.isPassable(VectorNode.java:153) at net.Citizensnpcs.api.astar.pathfinder.VectorNode.getNeighbours(VectorNode.java:104) at net.Citizensnpcs.api.astar.AStarMachine.run(AStarMachine.java:85) at net.Citizensnpcs.api.astar.AStarMachine.runFully(AStarMachine.java:120) at net.Citizensnpcs.npc.ai.AStarNavigationStrategy.update(AStarNavigationStrategy.java:83) at net.Citizensnpcs.npc.ai.MCTargetStrategy$AStarTargeter.setPath(MCTargetStrategy.java:152) at net.Citizensnpcs.npc.ai.MCTargetStrategy.update(MCTargetStrategy.java:119) at net.Citizensnpcs.npc.ai.CitizensNavigator.run(CitizensNavigator.java:164) at net.Citizensnpcs.npc.CitizensNPC.update(CitizensNPC.java:274) at net.Citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC.B_(EntityHumanNPC.java:158) at net.minecraft.server.v1_12_R1.World.entityJoinedWorld(World.java:1640) at net.Citizensnpcs.nms.v1_12_R1.util.NMSImpl.tick(NMSImpl.java:1018) at net.Citizensnpcs.util.NMS.tick(NMS.java:289) at net.Citizensnpcs.util.PlayerUpdateTask.run(PlayerUpdateTask.java:36) at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftTask.run(CraftTask.java:71) at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java :353) at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:738) at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) at java.lang.Thread.run(Thread.java:745)

CPU overloads to 95%.
Used Last Jenkins update &131 (22.8.2017 15:06:30)

NPC info:

  • Meleeattack
  • max chase range 25
  • max range 25
  • targetforget 100 (doesnt matter what I choose here)
  • target monsters

@mcmonkey4eva
Copy link
Member

Try build DEV-133+ off http://ci.citizensnpcs.co/job/Sentinel/
and lemme know if it still occurs.
(I pushed a relevant change that might help)

@GreenFlagCZ
Copy link
Author

GreenFlagCZ commented Sep 3, 2017

I tryied this last version, still have problems :(

@mcmonkey4eva
Copy link
Member

Might have to elevate this to Citizens then, as this issue is related to pathfinding buggery.

For a quick fix, lower all ranges, especially /npc pathrange.

I did what I could on my end (in the commit in DEV-133) to prevent re-triggering the pathfinder when there's no point to it... but if it's retriggering itself, that's a Citizens fault probably.

@mcmonkey4eva
Copy link
Member

I'm thinking about a potential semi-solution for this:

Catch the case if pathfinding fails, and intentionally delay any further pathfinding attempts for a while.
This runs the risk that players can easily troll the AI by blocking the path momentarily (placing a block, or jumping to a higher spot) to disable the pathfinding, then fight it, then jump back before it reengages pathfinding.

Also I think I haven't mentioned here already:
If you set use-new-finder to false in the Citizens config it's likely to run much more efficiently in this case (though at cost of some pathfinding accuracy).

Also see for relevance, Citizens issue CitizensDev/Citizens2#1561

If you'd like me to add an option for the idea I mentioned above or similar, let me know. Until then, treating this issue as out-of-scope for a Sentinel fix (instead, it should be fixed in Citizens).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants