Database performance question.

Discussion in 'Spigot Plugin Development' started by tokyojack, Jun 5, 2017.

  1. Hey!

    If you're using a SQL database for a plugin, would it be more efficient to store the data in an Arraylist and add that data to the database whenever the plugin is disabled, or to store the info straight into the database whenever the data is added. I'm leaning towards the second option, but I just wanted to confirm this before I complete the plugin.
  2. It depends on the data that you're handling. If it's going to be a massive amount of data then it's probably not good to bulk it all up and add it when your plugin is disabling. That can take a while, and if it runs into an error then you may lose all of the data that was accumulating over the server up-time.

    It's generally good to update the database when you get the data than to wait to add it all in at once.
    • Agree Agree x 1
  3. Hmm, you do bring a good point. My first guess was correct then.

    EDIT: If you're just storing data for just a single server and not throughout a network, would it be easier and more efficient to store in a config/flatfile, or just to put the info into a SQL database.
    #3 tokyojack, Jun 5, 2017
    Last edited: Jun 5, 2017
  4. Generally much faster to always use SQL if possible.
  5. If your not storing information constantly, i'd just use a flat file. However If you want access to those arrays on another server, id use Database. Already said by someone above but just giving another opinion :p
  6. That's not what he asked. If your server crashes and you intend to save data onDisable then the data won't save. I suggest either updating every so often with cached data, or update each time something happens. If a lot of data needs to be saved at once, I suggest batching the data.

    Sent from my iPhone using Tapatalk
  7. Yes, read his edit. He asked which was more efficient.
  8. Save data to object, then from object into mysql.
  9. Lets say I had an arena setup, where players would be placed in arenas to fight (or practice). Would it be better to load the arenas in the onEnable from the config to an ArrayList or to just to have the plugin search the configs for the required info(Spawn locations, arena type, etc.)?
  10. Depends. Retrieving cached data is faster than pulling information from a file and assembling it. If you intend to have a predefined amount of worlds, say 10, then you should load them in onEnable. However, and I do this personally, I would load the worlds into a directory created by the plugin, and load them as you need them, naming them something unique each time. This way you can have multiple instances of the world for your plugin, meaning multiple players can play on the same map, but different world. Make sure to remove the world after you are done with the arena however.