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

Player NPC always keeps chunks loaded #1947

Closed
SupppRabit opened this issue Sep 12, 2019 · 19 comments
Closed

Player NPC always keeps chunks loaded #1947

SupppRabit opened this issue Sep 12, 2019 · 19 comments
Labels
Bug Report A bug was reported. Research To Do The development team needs to research the issue.

Comments

@SupppRabit
Copy link

SupppRabit commented Sep 12, 2019

When I create a player npc, it always keeps chunks loaded whether it is in the playerlist.
But the wiki shows if you issue /npc playerlist, it'll become a 'real' player and load chunks. That's to say if an npc is not a 'real' player, it won't keep chunks unless users get close.
When I'm in another world or far enough away from the npc and type /mem, it shows more chunks are loaded.
The config always-keep-loaded had already been set to false.

Server: Paper 1.14.4 - 187
Citizens: 2.0.25-SNAPSHOT (build 1746)

@ScuroK
Copy link

ScuroK commented Sep 17, 2019

maybe thats why citizens is causing so much lag since 1.14.4 update?

@mcmonkey4eva
Copy link
Member

Citizens is not causing lag. 1.14 is lagging because 1.14 is a wreck.

@ScuroK
Copy link

ScuroK commented Sep 17, 2019

i do agree. but however when i use "React-smart server performance" to detect lag, react would often report citizens as "guilty" plugin. after removing citizens and sentinel, my lag problems are much much better. it seems like it IS a minecraft issue BUT citizens seems to be very strongly affected by it.

@mcmonkey4eva
Copy link
Member

Plugins like that (and also the native timings system) are incredibly inaccurate at best. Use a legitimate profiler (like Warmroast, VisualVM, YourKit, ...) if you want useful perf tracing information.

@ScuroK
Copy link

ScuroK commented Sep 17, 2019

ok. but removing citizens improved the situation so much that i am quite sure about it.

@fullwall
Copy link
Member

Not going to say that I understand the latest PlayerChunkMap code but something changed and may have broken this.

@mcmonkey4eva
Copy link
Member

This might have been fixed by the fix for #1822

Please test on latest dev builds

@mcmonkey4eva mcmonkey4eva added the Waiting For Reply The user needs to reply to this issue before we can continue. label Oct 29, 2019
@SupppRabit
Copy link
Author

SupppRabit commented Oct 30, 2019

I tested for several times on build 1770 and found there are many situations. Here is the rough result.

a
b
c
d

'd' depends on the view-distance settings, calculated by chunks. For example, if view distance is set to 12, d will be 27 and d^2 will be 729, which is the amount of loaded chunks when only one user in the server. Spawn point is at the default position in the initial overworld and about (0, 0) in the Nether, End and other worlds which generated manually with Multiverse plugin.

Green: only one user in the server
Red: one user and one player npc in the server. (same line and direction)

@mcmonkey4eva mcmonkey4eva added Bug Report A bug was reported. Research To Do The development team needs to research the issue. and removed Waiting For Reply The user needs to reply to this issue before we can continue. labels Nov 19, 2019
@Frumple
Copy link

Frumple commented Jan 14, 2020

Hi, I'd like to confirm that this bug is still occurring with Citizens 2.0.26 build 1808 running on Paper 1.15.1 build 42. The always-keep-loaded setting in the Citizens config is set to false. If it helps at all, I'd like to provide a much more straightforward list of steps to reproduce this issue using the Multiverse and EssentialsX plugins:

  1. Start with a server that has 2 worlds with only yourself online. For example, on our server we have a world called 'new' as our main world, and another world named 'old'.
  2. While on the new world, make the old world not keep chunks in memory by running: /mvm set memory false old
  3. Run the Essentials /lag command to confirm that there are no chunks loaded on the old world whatsoever:
    a
  4. Teleport to the old world: /mv tp old
  5. Create a brand new NPC somewhere on the old world: /npc create bob
  6. Teleport back to the new world: /mv tp new
  7. Run /lag again to see that chunks are still loaded on the old world even though there is no real player there:
    b
  8. If you delete the npc with /npc remove and run /lag again, it will show no chunks loaded on the old world like before.

I'd also like to note that this issue seems to be only happening for newly created NPCs. We have a bunch of existing NPCs on our server that were created before with Citizens 2.0.24 build 1628 for MC 1.13.2, and they do not keep our chunks loaded after we updated Paper and Citizens.

Hope this helps, thanks!

@mcmonkey4eva
Copy link
Member

I'd also like to note that this issue seems to be only happening for newly created NPCs. We have a bunch of existing NPCs on our server that were created before with Citizens 2.0.24 build 1628 for MC 1.13.2, and they do not keep our chunks loaded after we updated Paper and Citizens.
It's lines like this that indicate there's something more going on than just the simple form you might expect at first. (But also might benefit towards finding the underlying issue)
What makes those NPCs different? Is it that the server has restarted between their initial creation and now? Is it a setting that's different on those NPCs vs new ones (which would be visible in saves.yml)? Did you create that new NPC somewhere different from your preexisting NPCs (maybe this new one is in the spawn region and the old ones aren't, or something like that)? Is it just an NPC has to be near a player once, then it loads chunks forever, but otherwise won't?

@Frumple
Copy link

Frumple commented Jan 16, 2020

Is it just an NPC has to be near a player once, then it loads chunks forever, but otherwise won't?

Yeah, I think it's pretty much this. In my initial testing, I wasn't near any existing NPCs and forgot to try to go near one. I just tried it now, and the existing NPC is behaving just like any new NPC, keeping chunks loaded indefinitely even after I teleport to another world.

If I restart the server after going near an NPC, the chunks around them become unloaded and only become loaded as soon as I go near them again.

@mcmonkey4eva
Copy link
Member

Tested locally, CraftBukkit version git-Spigot-492a779-731e819 (MC: 1.15.1) + Citizens version 2.0.26-SNAPSHOT (build 1804)
(slightly behind but close enough)

1: At spawn-ish area. Checked loaded chunk count: 574
2: Flew several hundred blocks west.
3: /npc create bob. Checked loaded chunk count: 874 (about 300 higher than previous test)
4: Flew back to spawn-ish area. Waited a moment, checked loaded chunk count: 574 (same as original test)
5: Flew straight north several hundred blocks.
4: /npc create joe. Checked loaded chunk count: 1020 (almost 500 above baseline)
5: Flew back to spawn-ish area, waited a moment, checked again... 574.

Note that I checked via Denizen /ex narrate <player.world.loaded_chunks.size>.
Plugin list: Citizens, Sentinel, Denizen. Nothing more.

In summary: I cannot replicate this at all on a clean test server.

@mcmonkey4eva
Copy link
Member

mcmonkey4eva commented Jan 16, 2020

Tested on Paper-31 as well just to try, almost the same results except the chunk count rose to 600 after loading more in and didn't go back below that.

EDIT: Actually it did eventually fall down to... 576. Paper seems to just be really really slow at unloading chunks.

@mcmonkey4eva
Copy link
Member

Going to suggest y'all test without other plugins involved (Y'all seem to both be using Multiverse, which is rather high on the list of plugins I'd consider suspicious).

If you can replicate the problem on a clean/minimal server, please do post the details below and I'll reopen this issue.

@SupppRabit
Copy link
Author

When a user flies to hundreds of blocks away from spawn-ish area, the count of loaded chunks is much higher. Is that a problem?

@mcmonkey4eva
Copy link
Member

No, that's normal. Spawn generally remains loaded continually in minecraft, so there's a certain minimum number of chunks that will always be counted, plus however many the player's have loaded

@Kas-tle
Copy link

Kas-tle commented Jan 16, 2020

Stripped down my plugins to LuckPerms, Vault, Essentials, EssentialsSpawn, Citizens. Tried with CraftBukkit, Paper, and Spigot. All produce the same issue using the 1.14.4-R0.1 API. I spawn an npc, leave the server, and check /lag through console with essentials. It shows that chunks are loaded at the normal render distance. If I remove the NPC, half the chunks are loaded. So either its one of these 5 plugins (not sure what any of them would be doing with chunk loading) or something in my bukkit.yml that's bad, or something else I'm not considering. Would be happy do more testing if it would help.

@Kas-tle
Copy link

Kas-tle commented Jan 23, 2020

@mcmonkey4eva just was wondering if you would consider reopening this issue. I am now using Paper-67 (1.15.2) and am still having the same issue with only Citizens, Denizens, and Essentials installed. I have done quite a lot of testing so I will try to divide this up as best I can. This is all done on a newly generated world, with doMobSpawn set to false to make what is happening as clear as possible.

Using essentials:lag, I have no chunks loaded in my world before a player joins as I have set keep-spawn-loaded-range: 0 and keep-spawn-loaded: false in paper.yml. Firstly, it seems that the presence of player NPCs on the world completely negates these two settings. Spawn chunks remain loaded as soon as an NPC is spawned onto the world. So simply spawning any NPC away from the spawn chunks actually causes paper to immediately load in the spawn chunks, causing my chunk count to double. When using view-distance=10 in server.properties, this means that loaded chunks increase from 529 with only a player on the world to 1058 when a player NPC is spawned. Removing the NPC brings the loaded chunks back to 529. If I leave the world with the NPC loaded, the loaded chunk count then decreases to 530.
As Rabit points out, this issue seems to become amplified with view distance.

On leaving the world with the NPC, it seems that at view-distance=10, only a single chunk is loaded for the NPC (The total is 530. We would expect 529 as spawn chunks are 23^2, which is equal to 529). If we bump this up to view-distance=11, however, the loaded chunk count jumps to 626. If we increase to view-distance=12, this jumps to 730. On first glance, this seems that more chunks are being loaded around the NPC. However, I do not believe that is what is happening. You will note that 530, 626, and 730 follow the format {[(2*viewdistance)+3]^2}+1. So what appears to be happening is the spawn chunk radius is somehow being increased to the view distance. This behavior does not occur when no NPCs are loaded. If we decrease to view-distance=9, this behavior continues with 442 chunks being loaded. Further confirming this, adding an extra NPC brings this total up to 443. These values also match with those achieved by Frumple's example.

I have also tested setting the NPC to types other than player, and this issue does not occur in that case. Removing the npc via console brings the loaded chunk count to 0 as would be expected with these settings.

I can understand why this issue would be easy to miss, as at the standard view distance of 10, with only one NPC loaded, the number of chunks kept loaded is negligible. However, for those trying to achieve a performance boost by keeping unused worlds unloaded, this is an issue.

Edit[1]: These results are also reproducible without Essentials, using paper chunkinfo, but you must subtract "Inactive" chunks from "Total" chunks to get the loaded chunk value. This is because Paper keeps track of how many chunks have been loaded since the server came online. "Total" chunks value also resets if loaded chunks reaches 0.

Edit[2]:Also, this does not appear to be reproducible on normal Spigot, at least with the default configurations of Spigot in the 1.15 versions, as well as with the configurations I was using to produce it in 1.14.4, so it would seem something changed somewhere along the line with that.

Edit[3]:Reproduction Steps

  1. Create a clean server with the latest build of Paper 1.15.2 (Tablist #67 at time of test)
  2. Install EssentialsX for chunk counting (Paper alone may be used, but you must subtract "Inactive" chunks from "Total" chunks to get the loaded chunk value. If using this method, substitute lag for paper chunkinfo in later steps).
  3. Start server and accept EULA to create configuration files.
  4. Set keep-spawn-loaded-range: 0 and keep-spawn-loaded: false in paper.yml.
  5. Restart server, join, and /tp 0 100 1000 to get far away from spawn chunks.
  6. Run lag and note the number of chunks loaded.
  7. Run npc create foobar to spawn an NPC
  8. Run lag again. The number of chunks loaded should have roughly doubled due to the loading of spawn chunks.
  9. Leave the server.
  10. Run lag from console and note the number of chunks loaded.
  11. Run npc delete foobar from console.
  12. Run lag from console. There should now be 0 chunks loaded.

@fullwall
Copy link
Member

Sounds like the issue is now about spawn chunks not all chunks. Please open a separate issue and I can investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report A bug was reported. Research To Do The development team needs to research the issue.
Projects
None yet
Development

No branches or pull requests

6 participants