Configurations and performance.

Discussion in 'Spigot Plugin Development' started by Jagerborn, Jun 19, 2016.

  1. I have a plugin that writes to a config file on PlayerJoinEvent if the player is a new player.
    Then it saves the config, sometimes this can cause performance issues.


    - Would it be necessary to save the config every time a unique player joins?

    - How often do I need to save/load a plugin configuration?

    - Would it be okay to just load config onEnable and save config onDisable?

    - What is the best way to store information to a file without causing performance issues?

    Thank you for your time.
     
  2. You could store your data to a List and only save it onDisable. You could also write it to the file upon join but only save onDisable. It depends on how this data needs to be accessed. Is it data that is accessed while the server is running or is it long-term storage data?
     
  3. I'm rather surprised it's causing a performance issue. How much data are you saving and how do you know the file I/O is the cause?

    In a number of my plugins I save/load player state on events such as world change and haven't noticed any issues. In theory you should only need to save in "onDisable" but if the server/JVM goes bang then you could end up with data loss, how much of an issue this is for you depends on what you're saving.
     
  4. I thought about this, but wouldn't I also be required to save it every once in a while to be on the safe side? In case the server crashes. The data needs to be accessed while the server is running.

    Do you think it can cause performance issues if the file that is being saved is rather large even though the change is quite small.
     
  5. I don't know how Windows handles this but on Linux the disc write is asynchronous so "saving" the file is very quick regardless of the disc I/O speed, the kernel will write the changes to disc in another context later.
     
  6. Because the data is accessed while the server is running, if you were to only save onDisable, you would only have data from the last onDisable. To counter this, you could use a scheduler to do a large save every (5? minutes) or you could add a hook that allows you to save the config only when you need to. Example: you must access the data when someone does /command, when someone does /command, you save the config then and also access the now new data.

    As said above, it's odd that this is causing performance issues. Efficiency is key in this case, grind it down until it works flawlessly.