Solved Local vs Database

Discussion in 'Plugin Development' started by hanahouhanah, Sep 5, 2015.

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

    hanahouhanah

    I saw a few threads regarding this as well but the conditions were different enough to the point where I thought I should make my own thread to specify my situation and how I want to go about things.

    Say for example this plugin will be for a larger server which may get 100-200 players on it at a time. Currently, I have it so if a new player joins it'll create its own YAML file, have things added to it, and then have those values loaded into individual hashmaps for temp storage ingame. When the player leaves (for any reason), the hashmap values are then placed into its relevant section in the player's YAML, then saves.
    Those are the only two times the YAML will be accessed and used. The rest of the data is stored and used for manipulating in hashmaps. I feel that whether or not I use a database, hashmaps will be used for ease-access for the manipulation of values assigned to players. So in a sense, this whole idea is of storage method, and each yml file should be no more than 15kb.

    But, for the sake of confirmation and maybe just grabbing other people's opinions, would it be better to store the data in a database or through local YAML files, given the conditions and methods above? "Better" in terms of performance/resource usage, and possible things that could or couldn't go wrong.
     
  2. Offline

    Xerox262

    What kind of stuff are you storing in the files?
     
  3. Offline

    hanahouhanah

    Integers/Doubles, strings, one array string, normal stuff.
     
  4. Offline

    Zombie_Striker

    @hanahouhanah
    Even with 100-200 players, performance should not really be an issue with most servers and even databases would need to save the data to a file, so there really isn't a bad choice. I personally would use configuration sections for YML files to store data.
     
  5. Offline

    mythbusterma

    @hanahouhanah

    A ConfigurationFile is stored as a HashMap in memory, so there's no reason to do what you're doing.

    A database, unless you actually need it, will cause you a lot more pain than it's worth.
     
  6. Offline

    hanahouhanah

    Alright, will do. Thanks :)

    Not quite sure I understand what you mean. It's much easier to access and manipulate something like:
    playerExample.get(uuid) rather than
    YamlConfiguration yml = new YamlConfiguration();
    yml.load(theFile);
    SomeValue someVariable = yml.getSomeValue("somelocation"); And not to mention, something like that would definitely use more resources as it needs to access the contents of the files. Doing so per hundreds of players for everytime something must be manipulated would be a bit much and redundant. Suppose I could put each of them as methods for an API, but that could already be done as a hashmap, where the contents are just stored into memory rather than needing to constantly go through files, saving the files, etc.
    That's why it's about how I'm accessing it, not why I'm using hashmaps.
    -
    If I have a misconception, let me know. I rarely ever use Bukkit and thus have not been completely exposed to how YamlConfigurations actually work in detail. I just kinda assume they're like normal files and therefore work like normal files.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  7. Offline

    mythbusterma

    @hanahouhanah

    When you instantiate (or load) the Yaml file, it reads the entire file at load time, and stores what it reads into a HashMap.

    Doing ConfigurationSection#get(...) is actually just a HashMap lookup, and nothing is written or read until you call FileConfiguration#reload() (or whatever that is) or FileConfiguration#save().
     
    nlthijs48 likes this.
Thread Status:
Not open for further replies.

Share This Page