Commit Graph

4613 Commits

Author SHA1 Message Date
Spottedleaf
88092fef13
Optimize ChunkProviderServer's chunk level checking helper methods
These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.
2020-04-16 23:47:15 -04:00
Aikar
01e8ce8d2d
Forced Watchdog Crash support and Improve Async Shutdown
If the request to shut down the server is received while we are in
a watchdog hang, immediately treat it as a crash and begin the shutdown
process. Shutdown process is now improved to also shutdown cleanly when
not using restart scripts either.

If a server is deadlocked, a server owner can send SIGHUP (or any other signal
the JVM understands to shut down as it currently does) and the watchdog
will no longer need to wait until the full timeout, allowing you to trigger
a close process and try to shut the server down gracefully, saving player and
world data.

Previously there was no way to trigger this outside of waiting for a full watchdog
timeout, which may be set to a really long time...

Additionally, fix everything to do with shutting the server down asynchronously.

Previously, nearly everything about the process was fragile and unsafe. Main might
not have actually been frozen, and might still be manipulating state.

Or, some reuest might ask main to do something in the shutdown but main is dead.

Or worse, other things might start closing down items such as the Console or Thread Pool
before we are fully shutdown.

This change tries to resolve all of these issues by moving everything into the stop
method and guaranteeing only one thread is stopping the server.

We then issue Thread Death to the main thread of another thread initiates the stop process.
We have to ensure Thread Death propagates correctly though to stop main completely.

This is to ensure that if main isn't truely stuck, it's not manipulating state we are trying to save.
2020-04-16 22:40:20 -04:00
Zach Brown
fdb8fe7807
Be less strict with vanilla teleport command limits
Just limit to the same valid location check as BaseBlockPosition, no
reason to restrict to the world border.

Ref: GH-3165
2020-04-16 21:19:42 -05:00
Zach Brown
0f06d38062
Restrict vanilla teleport command to within worldborder
Fixes GH-3165
2020-04-16 20:11:44 -05:00
Aikar
24d93aafa2
Fix Optional null issue - Fixes #3155
Also check class loader cache before locking to speed up cached hits to avoid the lock

wasn't gonna make a unique build just for that but can lump it in here.
2020-04-16 03:57:02 -04:00
Spottedleaf
eb71c5fa3b
Fix incorect timing of mspt
Move oversleep and all task execution back into the timed area...
2020-04-16 03:47:38 -04:00
Spottedleaf
1ca8043428
Optimise entity hard collision checking
Very few entities actually hard collide, so store them in their own
entity slices and provide a special getEntites type call just for them.
This reduces entity collision checking impact (in my testing) by 25%
for crammed entities (shove 130 cows into an 8x6 area in one chunk).
Less crammed entities are likely to show significantly less benefit.
Effectively, this patch optimises crammed entity situations.
2020-04-16 00:40:47 -04:00
Spottedleaf
b67a423768
Don't run entity collision code if not needed
Will not run if max entity craming is disabled and
the max collisions per entity is less than or equal to 0
2020-04-16 00:40:34 -04:00
Spottedleaf
bd9aa547d2
Optimise ArraySetSorted#removeIf
Remove iterator allocation and ensure the call is always O(n)
2020-04-16 00:21:32 -04:00
Gergely Sarkozi
78871d07dc
Make JavaClassLoader thread-safe (Fixes #3137) (#3144)
* Make PluginClassLoader thread-safe (fixes #3137)

* Clean up implementation of MT safe class loader

Co-authored-by: Aikar <aikar@aikar.co>
2020-04-15 03:39:39 -04:00
Aikar
81706e6268
Make the shutdown thread try to shutdown on main 2020-04-13 03:30:12 -04:00
Shane Freeder
8918245090
Prevent opening inventories when frozen 2020-04-13 07:33:46 +01:00
Spottedleaf
e6d395cc83
Port 04-Util.patch from Tuinity (#3136) 2020-04-13 01:34:18 -04:00
Aikar
59453f6675
Fix incorrectly loading chunks on a cancelled interact event
A players previous block break location is held onto permanently, and if
an interact event is cancelled, the client sends a stop breaking block packet
This then tries to update client about that old location.

This old location might then be in a now unloaded chunk, and it caused it to load.

We now also clear reference to it once abort destroy block is ran to stop trying
to send updates about the old block anyways.
2020-04-12 23:56:29 -04:00
Aikar
bdcc31caad
Let invalid positioned entities clean up previous chunk by the chunkCheck
I had did a few of the operations myself, which would have broken chunkCheck
from doing it itself, which would leave some state left in the original chunk
and thats not good....
2020-04-12 22:55:43 -04:00
Spottedleaf
92d2907d14
Multiple memory and performance optimizations (removing streams) 2020-04-12 19:34:56 -04:00
Aikar
748e6447e3
Improve the don't save entities patch per leafs feedback 2020-04-12 18:29:52 -04:00
Callahan
c096fe19fa
Port 20w15a Villager AI optimizations 2020-04-12 16:56:59 -04:00
Aikar
832687de70
Restore preventing saving bad entities patch to full effect 2020-04-12 16:50:50 -04:00
Aikar
df8eedeed0
Restore Optimize Pathfinding patch 2020-04-12 16:50:34 -04:00
Aikar
97b1cc361b
Allow shutting down server during a watchdog hang gracefully
If the request to shut down the server is received while we are in
a watchdog hang, immediately treat it as a crash and begin the shutdown
process. Shutdown process is now improved to also shutdown cleanly when
not using restart scripts either.

If a server is deadlocked, a server owner can send SIGUP (or any other signal
the JVM understands to shut down as it currently does) and the watchdog
will no longer need to wait until the full timeout, allowing you to trigger
a close process and try to shut the server down gracefully, saving player and
world data.

Previously there was no way to trigger this outside of waiting for a full watchdog
timeout, which may be set to a really long time...
2020-04-12 15:56:03 -04:00
Callahan
06044e2458
Async command map building
Reduces lag created on login and world change for sending the command map to client
2020-04-12 15:43:07 -04:00
DrHenchman
a4f066ccea
Fix method profiler inbalance introduced in a2a9ffe (#3132)
Fixes #3131
2020-04-12 02:41:57 -04:00
Aikar
c65dcad3eb
Don't delay chunk unloads during entity ticking
Leaf informed me this could cause ordering issues.

So, the risk if this occurring is lowered now anyways, but if an
entity causes a sync chunk load, it could process an unload...

We will tackle the problem better in a future commit

Also fixed another async-chunks=false issue
2020-04-12 00:42:28 -04:00
Aikar
bc17ce69d4
Delay unsafe actions until after entity ticking is done - Fixes #3114
This will help prevent many cases of unregistering entities during entity ticking

Currently delays Chunk Unloads and Async Chunk load callbacks

Also dropped mid ticking chunk tasks during entity ticking to reduce this risk
2020-04-11 23:22:40 -04:00
Aikar
5553e6b3e3
Disable Sync Events firing Async errors during shutdown
This is how it use to behave on Paper, and this is totally destroying
the ability to try to shut the server down gracefully during the
shutdown process as events firing on the watchdog thread are throwing
errors.

This isn't an issue on Spigot

This has caused me so many rollbacks on watchdog already :(
2020-04-11 23:22:40 -04:00
Aikar
e12c51d9bc
Use better variable for isStopping() API
Previous method only worked for a normal shutdown, and didn't include
when the server enters a closing state due to watchdog crashes

This is the correct variable to detect the server is in the middle of shutdown process
2020-04-11 23:21:33 -04:00
Aikar
586ee2bb11
Remove patch for MC-111480, fixed in 1.14
We were now starting entities at ID 2
2020-04-11 20:39:21 -04:00
Spottedleaf
09a942155f
Remove streams from Mob AI System
The streams hurt performance and allocate tons of garbage, so
replace them with the standard iterator.

Also optimise the stream.anyMatch statement to move to a bitset
where we can replace the call with a single bitwise operation.
2020-04-11 20:15:22 -04:00
Aikar
bb5c294ecf
Fix Disabling Asynchronous Chunks
This fix is for the few people who are using such low end systems that
asynchronous chunk loading hurts them rather than helping.

The previous build made paper crash if you turned off async chunks, and
this fixes that issue.
2020-04-11 17:15:41 -04:00
Aikar
089d83568b
Implement Chunk Priority / Urgency System for World Gen
Mark chunks that are blocking main thread for world generation as urgent

Implements a general priority system so that chunks that are sorted in
the generator queues can prioritize certain chunks over another.

Urgent chunks will jump to the front of the line, ensuring that a
sync chunk load on an ungenerated chunk does not lag the server for
a long period of time if the servers generator queues are filled with
lots of chunks already.

This massively reduces the lag spikes from sync chunk gens.

This is also a precursor to my next improvement to prioritize chunks
in front of the player (Frustum Priorization)
2020-04-11 04:46:21 -04:00
Aikar
fce69af70c
Use dedicated thread for main thread blocking chunk loads
In most cases, this change won't benefit much. However, there
exists the possibility that your Chunk Task threads are all busy
doing super slow work such as converting chunks.

If this occurs, the main thread blocking tasks, even at highest priority,
has to wait for some thread to become available.

This change gives us a waiting thread used only for main thread blocking
tasks, as well as an increased thread priority level, so that the OS
will give priority to this thread over the other threads.

This is more about guarantees, and won't be any real performanc boost
to anyone who has low or fast activity on their chunk tasks anyways.

But not all of us force upgrade our worlds, and this can be a life saver.

also reordered some patches because multiple PR's were merged.
2020-04-11 04:46:13 -04:00
BillyGalbreath
588b62e47b
Add tick times API and /mspt command (#3102) 2020-04-11 01:52:17 -04:00
Josh Roy
11de41c777
Add API MinecraftServer#isStopping (#3129) 2020-04-11 01:51:35 -04:00
Spottedleaf
942ff3c28e
My patches are under MIT (#3130)
* My patches are under MIT

Remove ambiguity between my patches on Tuinity and here.
2020-04-11 01:48:34 -04:00
Aikar
0ed6da7ab2
Fix issues with 167 causing crashes due to missing chunks - Fixes #3122
Forgot to flip the pending boolean back to false, causing it to copy
empty data on the next tick if nothing else triggered a load.

haven't managed to actually reproduce the crash others got, but did
verify that the bad copy was occurring erasing the data.

also fixed a bug with chunk load callback not executing before
another one was scheduled.
2020-04-10 14:11:46 -04:00
Aikar
23ee0a8a88
Fix issue with 0,0 chunks causing crash 2020-04-09 23:02:17 -04:00
Aikar
bc8fafb206
Updated Upstream (CraftBukkit/Spigot)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
183139d4 SPIGOT-5665: Improve loading spawn egg NBT
dec5df26 SPIGOT-5667: Can't add recipe without (vanilla) datapack

Spigot Changes:
ae72bf43 SPIGOT-5666: Customizable End City Seed
2020-04-09 21:33:10 -04:00
Aikar
ebbca5cedb
Drowned is a RangedEntity (fixes API for Drowned to support Ranged) 2020-04-09 21:33:03 -04:00
Aikar
83b03eee04
Don't move existing players to world spawn
This can cause a nasty server lag the spawn chunks are not kept loaded
or they aren't finished loading yet, or if the world spawn radius is
larger than the keep loaded range.

By skipping this, we avoid potential for a large spike on server start.
2020-04-09 21:22:21 -04:00
Aikar
3b3e38fd01
Fix issue with loading chunk during ticking chunks issue
Also speed up performance of copying pending/updating to visible by
directly copying the internal array data instead of putAll
2020-04-09 20:45:46 -04:00
Aikar
78431dcaef
Update test server startup script 2020-04-09 20:45:38 -04:00
Aikar
ab74bb4514
Speed up processing of chunk loads and generation
Credit to Spotted for the idea

A lot of the new chunk system requires constant back and forth the main thread
to handle priority scheduling and ensuring conflicting tasks do not run at the
same time.

The issue is, these queues are only checked at either:

A) Sync Chunk Loads
B) End of Tick while sleeping

This results in generating chunks sitting waiting for a full tick to
complete before it will even start the next unit of work to do.

Additionally, this also delays loading of chunks until this same timing.

We will now periodically poll the chunk task queues throughout the tick,
looking for work to do.
We do this in a fair method that considers all worlds, not just the one being
ticked, so that each world can get 1 task procesed each before the next pass.

We also cap the throughput of these task processes to 1 per world per 0.1ms or
200 max per tick, to ensure that high volume of tasks do not overload the current
tick time.

In a view distance of 15, chunk loading performance was visually faster on the client.

Flying at high speed in spectator mode was able to keep up with chunk loading (as long as they are already generated)
2020-04-09 02:25:18 -04:00
Aikar
f5dd491fce
Increase Light Queue Size
Wiz mentioned that large WorldEdit operations cause light to run on
main thread. The queue was small, set to 5.. this bumps it to 20
but makes it configurable per-world.

The main risk of increasing this higher is during shutdown, some
queued light updates may be lost because mojang did not flush the
light engine on shutdown...

The queue size only puts a cap on max loss, doesn't solve that problem.

Don't touch this unless you know you have a problem and ok with the risk.
2020-04-09 02:25:09 -04:00
Aikar
9ab693487f
Don't load chunks when attempting to unload a chunk
Big Brain Logic
2020-04-08 21:13:48 -04:00
Aikar
38c626229d
Improve Optimize Memory use logic to make iterator safer and fix bad plugins like P2
Accessing world state async is bad mkay. But we know you didn't do it city <3
2020-04-08 21:07:59 -04:00
Aikar
d33ba160a4
Fix incorrect keyword use on visibleChunksClone 2020-04-08 04:12:48 -04:00
Aikar
2f34301581
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
7361a62e SPIGOT-5641: Add Block.getDrops(ItemStack, Entity)
1dc91b15 Add specific notes about what is not API
2b05ef88 #484: Allow statistics to be accessed for offline players

CraftBukkit Changes:
f7d6ad53 SPIGOT-5603: Use LootContext#lootingModifier in CraftLootTable
5838285d SPIGOT-5657: BlockPlaceEvent not cancelling for tripwire hooks
f325b9be SPIGOT-5641: Add Block.getDrops(ItemStack, Entity)
e25a2272 Fix some formatting in CraftHumanEntity
498540e0 Add Merchant slot delegate
b2de47d5 SPIGOT-5621: Add missing container types for opening InventoryView
aa3a2f27 #645: Allow statistics to be accessed for offline players
2122c0b1 #649: CraftBell should implement Bell
2020-04-08 03:49:15 -04:00
Aikar
a65831bd69
Optimize PlayerChunkMap memory use for visibleChunks
No longer clones visible chunks which is causing massive memory
allocation issues, likely the source of Humongous Objects on large servers.

Instead we just synchronize, clear and rebuild, reusing the same object buffers
as before with only 2 small objects created (FastIterator/MapEntry)

This should result in siginificant memory use reduction and improved GC behavior.
2020-04-08 03:09:05 -04:00
Aikar
6c39a59ae7
Use entity.dead instead of entity.die()
Fixes #3096
2020-04-04 21:09:27 -04:00