This is a bug that has been in every version since about 1.6.
The problem is that monsters don't despawn when out of rendering range. For example: I can go to an area at night and have monsters spawn around me, then I leave, while it's still dark. And by leave I mean go out of chunk range. Any number of Minecraft days later, I can visit that same area again, middle of the day, and all the monsters that spawned [x] days ago will still be there, and won't start burning up/despawning until I can see them.
The problem with this is that the spawning/despawning code is not working properly, and I think it might be causing unnecessary lag.
Related issues
relates to
Attachments
Comments


Spawnchunks could cause this if the distance was perfect and the mobs were in shade.

Or the mobs came out of a nearby cave?

Yeah that's the thing though; it's out in the open plains in daylight, no trees or anything. And it's all the mobs that spawned, not just a few of them. I might try increasing my render distance to see if that helps, as I have it consistently at 5 chunks. I don't know if that makes a difference or not.
Another way to explain the issue is by comparing it to the Enderdragon freezing when it gets too far from the player. This happens with monsters but they don't despawn at that point, they just freeze until I go within range again.
The main reason this seems to be a problem to me is because I never saw it happen until about version 1.6. Before that monsters would automatically despawn when the player went out a certain distance. According to the wiki that's what's supposed to happen as well, but I'm just not seeing it now. :/

Ok I've attached a screenshot of me duplicating the problem. I went 90 blocks (which is about 5 chunks) from my house at night, let mobs spawn, then went back to my house. Slept through the night and then waiting until "noon" to go back to that area. The mobs didn't start burning or despawning until I could see them.
This does seem to be related to render distance in the video settings but again, mobs are supposed to automatically despawn when out of chunk range, instead of just freezing.

Oh... I do not know then. Thanks for the extra info.

No problemo. I didn't think about the extra stuff until you commented, so thank you as well.

Probably related to MC-2536/MC-42053. From what I remember, the low mob spawning bug was because on low render distances (<10), the mobs would unload before they despawn, preventing them from despawning. This raises the amount of entities, which prevents other entities from spawning (due to the entity cap).

Is this still an issue in the current Minecraft Snapshot 15w47c or later? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

I'm on a 1.11.2 vanilla server, and I'm experiencing this exact problem. I can do the command "/say hi @e[c=127]", and manually counting, there are 54 hostile mobs that respond. That number isn't changing with time. I'm logged on alone, so the hostile mob cap should be 70, but even with the difficulty set to hard, no mobs are spawning in this mob farm we built that's at Y=230 over ocean.
So there are mobs somewhere definitely >128 blocks away that are not despawning. And since this is the only place within 128 blocks of the player with a spawnable area, we should be getting lots of spawns, but it just isn't happening.
I'm an Op, but I don't have console access. What commands can I enter to help diagnose this?

I've done some investigation on this. First of all, that say command seems to only apply to mobs in loaded chunks, which makes sense. There have been times when lots of people were on this server, so the mob cap has been really high at times.
I tried an experiment. I entered the command /tp theosib @e[type=Zombie] over and over and found two major concentrations of mobs on this server. One near spawn, and the other near someone's island at -8500/1100, where I started diagnosing this problem. Then I tried killing them with "/kill @e[type=Zombie]". I don't know how many are killed off at a shot, but I'd say that I had to repeat that command at least 6 times before they all died. The same pattern happened for other hostile mob types. There are just massive numbers of them.
Now, if I'm the only one on the server, I would expect that any mobs in loaded chunks but > 128 blocks away from me would despawn. But I think the main root of this problem is that this just isn't happening. I was on alone for quite a long time before I started doing this tp and kill cycle. There should be zero mobs at spawn, yet I'm finding dozens of them. And there should be zero mobs in caves below where I started at around -8500/230/1100. They should have all despawned instantly.
EDIT: One other interesting thing. I'd say maybe 30% of the time when I tp to where a mob of a given type should be... there is no mob of that type in sight. That seems really strange too.

I've done some further experimentation. If I move horizontally 128 blocks from where mobs are, they are not longer accessible. I doubt they despawn, but rather, the chunks unload.
However, if I move vertically 128 blocks, nothing happens. According to all of the resources I have read, if you move a cartesian distance of 128 blocks from any mob, it should despawn. However, I can put myself into creative mode and teleport to Y=250, and this has no impact on hostile mobs.
My experiment:
Be the only player on a multiplayer server.
Set difficulty to hard.
Go to some non-spawn chunk and stand on the ground for a while during the day so that mobs can spawn in caves.
Go into creative mode and teleport to Y=250.
Wait 10 minutes. All hostile mobs should despawn immediately, but why not.
Enter a command that refers to some active hostile mob, such as:
/say hi @e[type=zombie]
/tp @e[type=skeleton]
Since I'm up in the air and more than 128 blocks from any place where a hostile mob could be, any such command should fail. However, instead I find dozens of hostile mobs still exist in the currently loaded chunks.
Can we please reopen this bug?
Thanks.

@unknown, the ticket is yours now. Please update it accordingly.

Thank you, Michael. It looks like someone has already added 1.11.2. Is there anything else I can do to help? Run experiments?
It may be possible for me to get a world download. Also, I can provide the seed, but for various reasons, I'd like to provide that privately.

Has this been reproduced in singleplayer, or is this strictly multiplayer?

To be honest, this is the first time I've encountered this problem with such severity, both multiplayer and single player.
I have seen LPers on youtube mention that spawn rates in mob farms drop when other users are logged in. I'm pretty sure that this shouldn't be the case since mob caps are supposed to increase with the number of users. But in any event, the problem goes away for them when the other users log out.
On this server of ours, the problem persists even when I'm the only one online. Mobs in unloaded chunks are not a problem, but mobs > 128 blocks vertically from the player are not despawning.
Since I'm an Op, I tried manually killing off all hostile mobs. Then I went >24 blocks above the mob farm and found spawn rates to be very high. However, once mobs are given an opportunity to spawn down in caves in the same chunks, the spawn rates in the mob farm plummet. My understanding is that MC will attempt to spawn mobs basically anywhere with the right light level in any loaded chunk, but if a mob is spawned that is > 128 blocks from a non-spectator player, it should immediately despawn. I have not yet attempted to explore this by logging on with multiple accounts, however, but my suspicion is that something is going wrong with the code that decides to despawn mobs outside of the 128-block sphere.
Note that when I google this problem I'm observing, I find plenty of forum discussions complaining about this going pretty far back. I'm definitely not the first person to encounter this problem. Would you like me to link you to some? Unfortunately, I didn't find them to be very informative in terms of what might be causing the trouble.
I will try to see if I can get a world download for this. For one thing, you should be able to analyze where the mobs are at the time that the server was shut down. But also, we can bring this same world up in single player mode and see if the spawning behavior is any different. Meanwhile, you are welcome to log on to this server. If you coordinate with me, I should be able to make you Op since I am an Op myself; if not I can at least put you into spectator mode.
Thanks again.

I now have full console access and the ability to download the world files.

On a hunch, can you check the value of view-distance
in server.properties
?

Huh. It's set to 6. That's very strange. I think this is some kind of mcprohost default file. I'm going to investigate into how it got to be this way. I forget what the default is...

Actually, the default is 10. I have not confirmed yet that setting it to 10 has completely fixed this, but in general, mob spawn rates shot up when we made this change. What we did notice is that the server memory demands also shot up, even with only two players online, which seems odd. I wonder if mcprohosting has their JVM arguments optimized properly, i.e. using incremental GC and such.
Now, if changing the view distance to 6 messed up the usual expected behavior of despawning mobs 128 blocks from the player, then this may reveal something about this bug. I get the impression that the view distance setting is having expected behavior horizontally – chunks unload, and mobs there don't affect the mob cap. On the other hand, vertically > 128 blocks, the mobs are definitely still loaded and definitely affecting the mob cap and seemingly still active to some degree. But the view distance is making it so that they don't despawn. In other words, the code is perhaps inconsistent in how it handles view distance vertically with regard to mob activity, spawning, and despawning, sometimes being affected by the view distance and sometimes not.
So, view_distance is a radius, in chunks, from the player that the server uses to decide what chunks to keep loaded. If we set that to 10, then (among other things) mob activity is being managed within a 160 block radius. Since mobs are supposed to despawn > 128 blocks, then this gives us a buffer on the order of 32 blocks where the server can notice that a mob is > 128 blocks form the player and despawn them.
On the other hand, if the view distance is set to 6 (apparently a default used by mcprohosting), then the server is only going to process up to 96 blocks from any user. That gives us a buffer of 32 blocks (between 96 and 128 from the user) where mobs can exist and contribute to the mob cap but will NEVER get despawned.
A major inconsistency here is that vertically, coordinates more than 96 from the user are STILL LOADED and therefore contributing to the mob cap, but the code that would despawn mobs > 128 from the player isn't even bothering to check that far away, which causes some major problems.
I think the spherical distance from the player for mob (de)spawning should be kept, and it should also be honored. So I think the best fix is to allow the despawn code to check for and despawn mobs outside of the view distance, as long as they are in loaded chunks. Maybe they won't spawn outside of the view distance, but that's not a problem. All the problems we encountered were caused by mobs not DEspawning outside of that range.

Please check if that's still an issue for you in 1.13.1.