Solved Faster storage option than YAML?

Discussion in 'Spigot Plugin Development' started by Sanfeanso, Jun 22, 2020.

  1. Hello, I'm trying to store some player data and I was curious if there is a faster storage option than YAML since I plan to update the YAML per kill, and I'm not too sure if that will lag out the server too much. And before you say "you should use a database!". I honestly don't know how to use a database, unless you want to show me xD. If you think that YAML should be just fine, then you can just respond that! Thanks!
  2. I mean.... YAML would work.... not sure how much it would lag but depending on how much information your actually putting into this yaml file, i dont really want to think of the potential file size. I know plugins which do things like block logging which are updated fairly frequently will use databasing of some description, which in my opinion i think you should use. Even if you dont really need to in this case its always good to learn different data storage techniques ;)

    Heres a link to a spigot wiki for integrating MySQL with your plugin to help you get started. Obviously theres more to be done with this but its a start.
    • Useful Useful x 1
  3. I'm probably going to test out YAML just by running my yaml saving code a lot and see if the server lags. If the server lags, I'll start looking into databases (likely SQLite). Thanks for the help! I really appreciate it! (btw each yaml file only holds 5 integers, just if you were curious)
  4. Yes, I strongly suggest using MySQL. When it comes to YML files, it can be very server intensive to continuously save to it.

    If you want to use YML’s, the better way would be to create an ArrayList or Hashmap with the information, then save all that information to a YML file when they leave.

    For example, when a player logs on, get the “players.killed” integer from their YML and put it into a Hashmap with their UUID. Then, everytime they kill a player, add a number to that Hashmap. When they leave, take that number and save it onto their YML file. That way the file is only ever being loaded/saved when they enter or leave the server.
    • Agree Agree x 1
    • Useful Useful x 1
  5. You can just cache the data temporarily to a map or something and modify it while it's running as needed. Then only write the collected data when the plugin shuts off. Once it starts again load it back up from the file. That will minimize the amount of times you're reading and writing to the file.
    • Useful Useful x 1
  6. Whatever storage solution you chose, retrieve/save your data async and it should never lagg your server.
  7. How do I do that?
  8. Since you mentioned YAML, i suppose you could also be looking for file-based databases. Spigot 1.12.2 and up already have the Sqlite jdbc driver available at runtime so you don't need to go into shading (... unless you want a less outdated version :confused: ).
    As @SmokingIsBadMkay suggested, you should mainly use concurrent operations to save and read data from your database. Although not everything should be done that way, for example table creation\altering is something you want to be thread-blocking.

    I suggest you learn about Future interface and CompletableFuture, they're one of the simplest ways to perform concurrent tasks and have many advanced features: