WorldGuard

WorldGuard

8M Downloads

MySQL : could improve x100 speed quite easily

LadyCailinBot opened this issue ยท 6 comments

commented

WORLDGUARD-3104 - Reported by fastlockel

I went through the MySLQDatabase Code and understand why it is so slow !
It loads all, saving all, and even worse, when saving : all regions are loaded again in order to delete previous database content ! and recreate all.

The best would be to have an API to save one region, not saveALL, but this would be a change in other parts of your code and could be complex.

A WORKAROUND, you could very easily implement would be :

  1. store last_modification_time as a long attribute on your region object : initialised with System.currentTimeMillis();
    Update this when a command updates a region !
  2. In mysql connector also store load time as an attribute (load_time) when loading regions.
  3. in the 'hugly' saveall of MySQL just ignore regions which have last_modification_time < load_time ...
    The methods which modifies regions, call saveAll but should update last_modification_time before calling saveAll.
    If deleting a region, set a boolean_attribute (deleted = true) or set a negative identifier so connectors like MySQL have deleted regions

which should be 99.9% of regions ! And forget about reading them all, re-read only modified.
This would still be much slower than a 'real proper' Sql update, however hundred times faster than current code.
Additionally preparedStatement should be kept in loops and be reused.

commented

Comment by wizjany

we know (see linked issue)

commented

Comment by fastlockel

yes but between a full efficient rewriting of the database API, would be great but needs times.
You may juste add a simple trick to know if a region as been modified or not : every command specify the region name, when you fetch the region change modification time (even if not modified by the command) : with worldguard a region is very stable : modification are extremely rare!

commented

Comment by sk89q

The MySQL implementation also over-normalizes -- all the points in polygonal regions are individual rows in their own table which is pretty pointless.

At the moment, my main focus is WorldEdit and adding a lot of long-desired features, so I'm not working on WG at the moment.

commented

Comment by fastlockel

Ok I understand, however worldedit is nice feature to have and speed up design, but if you loose all your worldguard claims because of a server crash or out of disk space or for any reason this is a very critical issue.
Three times I had corruption in the yml file, regions not loaded all protections removed without notice and took few hours to discover that a lot of players greif the whole map. Took me hours to restore to normal. I might have a closer look at it but do not know if this a centralized work you do for the plugin or if this is a commnity collaborative design ?

commented

Comment by sk89q

It's open source: https://github.com/sk89q/worldguard

Lots of code in WG is community-contributed, though some of it is not so good. There are also two dozen pull requests open, but I do not have time to look over them at the moment.

commented

Comment by sk89q

Download a test version with the fix:
http://forum.enginehub.org/threads/worldguard-6-0-beta-build.15666/