Solved Async

Discussion in 'Spigot Plugin Development' started by GodCipher, Mar 13, 2020.

  1. Hi, guys,
    here i have already asked if i have to do the data query and setting data from/to a database asyncron.

    Now my question is...
    Should I also do the set/get data from/to files (YML) asyncron


    for example ->

    Code (Java):
    getConfig().set("Profiles.PlayerData." + offlinePlayer.getUniqueId().toString() + ".Stats.Deaths", amount);

    //

    getConfig().getInt("Profiles.PlayerData." + offlinePlayer.getUniqueId().toString() + ".Stats.KilledEntitys");
     
  2. From the looks of it this is the regular config. It gets loaded into ram on server startup so it's not required to be read/written async as it's all in memory anyway. The gain is really not worth the trouble
     
  3. Only thing you could do async here is saving YamlConfiguration to the actual file if you are even handling that part but even that would only have small benefit assuming the amount of things youre saving is quite large. If its not then no need for async when working with YML files.
     
  4. The purpose of an async save is because I/O blocks. The amount of time the operation blocks for is not simply a function of how much data is being read or written, but also factors how busy the disk is with other I/O requests, waiting for the hardware memory bus to become available, memory bandwidth, etc. For all we know, a syscall to the OS to write data is even allowed to have Thread.sleep(5000) before writing your data. It doesn’t, but there’s little distinction between a long running blocking operation and literally just sleeping, which is why it’s important to never perform I/O operations on the main thread. I’ve crashed production servers forgetting this on numerous occasions.
     
    • Informative Informative x 1