Storage of data

Discussion in 'Plugin Development' started by guitargun, Jul 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    guitargun

    So my plugin loads data from a database, flatfiles and yml files, stores them in a map and leaves them there until needed. My question is, on what point is it better for me to get the data when it is needed to be loaded in for not causing any performance issues. Also is it better to use a database or just flatfiles/yml files for storage
     
  2. Offline

    blablubbabc

    Depends on the type (when and how often is it used) and amount of data you store.

    If you know that the overall data amounts will stay relatively low, you can load them all when the server starts and then keep them cached in memory.
    If it's data which you need to access frequently, or if it's data which needs to be loaded before a certain event happens, then pre-loading and caching seems to make sense as well.
    If it's (lots of) player data which you mostly only need when the affected player is online, you could design your caching strategy to keep this player data always loaded while the player is on the server.

    Just make sure that the loading of the data, whenever it should happen, is done in a separate thread (you can use the async tasks of the bukkit scheduler for that). So that the time it needs to load the data is not noticeable affecting the server's performance for the players.
     
  3. Offline

    Hawktasard

    @guitargun
    Using a database for data storage is "more advanced" (if you know what you're doing it's actually quite simple).
    I personally use a database if I need to use the data on multiple machines (many servers, website, etc) and flatfile if it's only for one server/machine.

    I'm pretty sure everything in a YamlConfiguration (getConfig(), etc) is loaded into memory, so you should be able to get things from there really fast and not have to worry about it (as long as you don't have a lot of data in there).

    If I'm working on some kind of "network" I usually load player data and all that good stuff from the database on another thread when they join, so the server will not freeze while I do that, but if for example you'd want the motd (for all the servers) to be editable from the database I'd load that on startup.
     
  4. Offline

    guitargun

    @Hawktasard so I have made some sort of quests. is this better to let it be cached or called when needed?
     
  5. Offline

    Hawktasard

    @guitargun
    I'd load the quests on startup, but if you want to load the player's "progress" you should do that when they join.
     
Thread Status:
Not open for further replies.

Share This Page