Game breaking Lag
vadis365 opened this issue ยท 20 comments
This has been reported several times by different people but never addressed.
@chylex has always blamed forge/vanilla for it but that is plainly not true.
Something is definitely broken, I'm not sure where it is but it looks like there is a re-cursive loop happening somewhere that is causing only certain chunks to freeze. Chunks next to frozen chunks seem to be unaffected. I personally don't think it is mob spawning causing this. There may be an issue with one of the mobs or something. I have been provided with a world seed and co-ordinates of a set of laggy Chunks by @Darkosto and @Funwayguy who have this issue (thanks guys).
Seed: "-9203439170981527153"
X: 104 Y: 27 Z:441
The chunk lag, freezing, whatever seems to be affecting already generated chunks which would lead me to believe that worldgen/decoration isn't the cause.
Time to start adding console prints to Everything!
https://github.com/ganymedes01/TheErebus/blob/master/src/main/java/erebus/world/SpawnerErebus.java#L73 -- You may be better off iterating over the loaded chunks and getting closest-player-distance inside the loop. You'd be able to change spawnChunks to an ArrayList. Would probably want to measure that tho.
https://github.com/ganymedes01/TheErebus/blob/master/src/main/java/erebus/world/SpawnerErebus.java#L92 -- You should have an Erebus entity base class, or listen to some forge events, that modifies a per-world entityCount as mobs spawn and despawn.
@Darkosto - thanks man that is awesome. I have been talking with the other active devs to get to the bottom of the issue.
When are you streaming next?
@purpleposeidon - thanks man - will talk to @ganymedes01 about this :)
@vadis365 I'll be streaming in about 20 mins and plan to do more modpack dev work :)
@Darkosto - good stuff - I'll pop by for some #BlameErebusForLag embarrassment ;)
Since I am doing extensive play testing using this mod for a new modpack, I can offer any assistance you may need. Just let me know if you would like me to help.
I have spoken to @chylex - the original author of the spawning system he says:
"hmm, not 100% sure about chunks around players vs nearest player to chunk, default view distance is 10 so it only benefits if you have lots of players in the same spot I think.
Using events for spawning is a good idea, but you can't detect when an entity is deleted using setDead instead of usual despawning, so you might just end up with no mobs spawning because the game thinks there are mobs everywhere.
I guess you could compromise by not running the entity detection cycle every single time, but only once every 1-5 seconds to refresh the data, and use cached data in the meantine?
Profile/sample it with jvisualvm, or use Stopwatch.timeAverage if that's still there.
I guess if it's around 1 ms, then you can just have a 4 tick delay and increase spawn rates 4 times, or something like that... if it's larger, then it's a proper problem"
Just to let everyone know that this is actually being looked in to and not ignored :P
I'm more curious as to why the algorithm needs to be there to begin with. I figured Minecraft's spawning algorithms worked just fine regardless of dimension. The only thing I can see that this algorithm would be doing is increasing the spawn density of mobs, which can be done in less process intensive ways.
Note: Using a co-routine like setup (one loop per tick instead of all of them at once) might make things a little less intensive if you must keep the code.
I wish I remembered... but there must have been some issues with the vanilla one, maybe someone else can remember (possibly some mobs not spawning because the game only respawns hostile mobs, and some issues with mob limits as far as I remember).
The thing is, the code is almost the same as what vanilla uses, it just has some extra features like limiting mobs per class and some additional conditions. It's entirely possible those extra features are causing the slowdown, but it needs to be profiled.
I'll also be doing some more work with the mod on stream today :) Just started up a few minutes ago.
Ran some tests on this - the spawner, when run at a reduced timer, works the same in lag chunks as non-lag chunks the lag remains. The spawner code doesn't seem to affect the chunk lag. If killing all mobs clears the lag in chunks then the problem is with one of the mobs. I will go through each mob and remove them from the game until the lag doesn't persist. Grasshoppers, Beetle larva and any other mob that has a more intensive AI could be the cause of this.
@Funwayguy and @Darkosto this in the EntityGasVent sets the Entity to dead after 20 ticks.
I have no idea why your opis log shows 1000's of them. It just shouldn't happen!
The massive climb in entity counts is VERY strange - could you clone the world you are using and just run The Erebus with opis to see if the entity count rockets up?
*Edit
There is a config option to turn off the dynamic lighting used by swamp wisps and glow worms - maybe turn the lighting off as this will remove the intensive lighting updates.
You could try making the 20 tick kill trigger run client side, just a guess that residual entities aren't being cleared client side.
Ran Opis whilst stood in the centre of a Submerged swamp biome. Stayed there for 20 minutes or so and my entity count didn't go above 350 or so EVER. I think another mod is causing the entity count to go through the roof, something exterior must be effecting mob de-spawning for the gas vents imho.
The Grasshopper and Beetle larva AI has been reduced in ticks a few commits back - I am hoping that this may reduce some of the lag as the AI will not be firing as often. It may help as opis already shows that the average Grasshopper tick is reduced by 4-5 times on the server load.
Changed the way glowing entities work now so the lighting updates will only happen when the player is within range of a glowing mob. This will stop any lighting updates happening in far off chunk borders which should remove any lag that would be caused by them. Going to close this issue for now as I think this has been the cause of the lag problems. If not I'll re-open the issue.
Sorry for the late response! This seems to have fixed the issue. No more lag that I can see :)
Is this fixed with the removal of the dynamic lighting on Mobs?
If this is the case I'll re-code them to only glow when a player is near - I have started this already but don't like the code as it is... will fix... soon.