MySQL vs save.yml

Discussion in 'Spigot Plugin Development' started by Eliminator, May 6, 2015.

  1. I am making a plugin that saves a fair bit of data, location players ect.

    Would it be faster to use MySQL then a save.yml?
  2. MySQL is best choice
  3. For something with a lot of bandwidth with frequent I/O, you should look into a database for convenience.
    You can always write a simple cache system and only write to a file occasionally. If you're handling megabytes of data though, you might want to look into a database.
  4. Not really megabytes of data, but how could connecting to a data base be faster then just saving to a file right on the server?
  5. A badly implemented flatfile system could i.e. parse the entire file when it needs to get just a single bit of data. And vice versa for writing. You could be rewriting the entire file each time you want to change one bit of data.
    With a database, you're only reading/writing the relevant bits of information. Drastically lowers overhead on larger amounts of data.
    • Agree Agree x 2
    • Informative Informative x 1
  6. Databases will always be faster than flat file when it comes to large amounts of information.
  7. Not if properly implemented. Databases aren't magical, and you can likely get better performance if you design a complex flatfile system specifically for your application. Databases are really just glorified flatfile systems.
  8. In general databases tend to be faster than flat files. The queries tend to be faster than parsing a flatfile unless you want to use or write a complex utility in order to read it.

    It makes more sense to use a database as opposed to a flatfile for storing large amounts of information.
  9. * In case of small things like plugins

    If you're working on a system designed to handle extremely large amounts of data with extremely high bandwidth, you should look into a custom solution. We're talking google-sized projects before you really benefit, but hey.
  10. So since its not a lot of data, and I write my files nicely so it never need to parse through the whole thing, its fine just to use it?
  11. No. If you're calling a YAML parser to look for a specific entry, you're parsing the entire file.
    Exactly what kind of data are you handling? Does it need to be accessed frequently?
  12. In a general sense, neither are better.

    @Eliminator it highly depends on when you need what amount of data. If it is plain storage, per player, rather small, then files will serve you well, and a database (as MySQL is not the only provider, I'm using database) is likely too complex.

    However, if you need global statistics, or need to share the data among services, then using files quickly becomes unmanageable.

    Pick wisely, based on context, never (solely) on opinion.
  13. YAML reads the whole file while loading, but if you save the returned FileConfiguration, the data is internally stored as a Map<String, Object>. Assuming this is a regular HashMap, retrieving data has the speed of the Map.
    This uses a little ram but probably nothing noticeable. If you are storing player data you could only load the data of online players for faster lookup and less memory, but you will have to read the entire file again on player login. That choice is yours depending on the amount of unused data and amount of lookups.
  14. OK, so I don't think there will be too much data, so YML should be fine, if there are lots of lookups I can read the YML on plugin load and save it to a has map, then re-save it to file on quit.
  15. You don't have to save it to a Map yourself, that's done under the hood by spigot. I was just explaining it from a performance point of view.