Updated-NoCheatPlus / NoCheatPlus

Anti-cheating plugin for Minecraft (1.5-1.21, Bukkit/Spigot)
https://ci.codemc.io/job/Updated-NoCheatPlus/job/Updated-NoCheatPlus/
GNU General Public License v3.0
486 stars 100 forks source link

Folia multithraeded Paper fork support #291

Closed xymb-endcrystalme closed 1 year ago

xymb-endcrystalme commented 1 year ago

https://github.com/PaperMC/Folia

First, Folia breaks many plugins. To aid users in figuring out which plugins work, only plugins that have been explicitly marked by the author(s) to work with Folia will be loaded. By placing "folia-supported: true" into the plugin's plugin.yml, plugin authors can mark their plugin as compatible with regionised multithreading.

The other important rule is that the regions tick in parallel, and not concurrently. They do not share data, they do not expect to share data, and sharing of data will cause data corruption. Code that is running in one region under no circumstance can be accessing or modifying data that is in another region. Just because multithreading is in the name, it doesn't mean that everything is now thread-safe. In fact, there are only a few things that were made thread-safe to make this happen. As time goes on, the number of thread context checks will only grow, even if it comes at a performance penalty - nobody is going to use or develop for a server platform that is buggy as hell, and the only way to prevent and find these bugs is to make bad accesses fail hard at the source of the bad access.

This means that Folia compatible plugins need to take advantage of API like the RegionScheduler and the EntityScheduler to ensure their code is running on the correct thread context.

In general, it is safe to assume that a region owns chunk data in an approximate 8 chunks from the source of an event (i.e. player breaks block, can probably access 8 chunks around that block). But, this is not guaranteed - plugins should take advantage of upcoming thread-check API to ensure correct behavior.

The only guarantee of thread-safety comes from the fact that a single region owns data in certain chunks - and if that region is ticking, then it has full access to that data. This data is specifically entity/chunk/poi data, and is entirely unrelated to ANY plugin data.

Normal multithreading rules apply to data that plugins store/access their own data or another plugin's - events/commands/etc. are called in parallel because regions are ticking in parallel (we CANNOT call them in a synchronous fashion, as this opens up deadlock issues and would handicap performance). There are no easy ways out of this, it depends solely on what data is being accessed. Sometimes a concurrent collection (like ConcurrentHashMap) is enough, and often a concurrent collection used carelessly will only hide threading issues, which then become near impossible to debug.

0-x-2-2 commented 1 year ago

We did this a few hours ago, it is mostly simple but will require a lot of testing to make sure everything is safe.

image (3)

ghost commented 1 year ago

We did this a few hours ago, it is mostly simple but will require a lot of testing to make sure everything is safe.

image (3)

than can you make fork to test ncp on folia?

Lysandr0 commented 1 year ago

Should be more or less done, do leave a note if otherwise.