Rant about using MySQL/File Systems in plugin.

Discussion in 'Bukkit Discussion' started by wow4201, Aug 1, 2012.

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

    wow4201

    Say you have a plugin where you gain 10 XP (Special XP that your plugin uses for whatever)
    Everytime you hit a block.

    You do not want to update the SQL database everytime you gain XP.
    What you want to do is. Create a hashmap inside java that holds all this information.
    Update that hashmap when the player hits the block or whatever.

    Then pass that information to SQL when the player logs out. Server stops or at an increment of time(ex every 10min).

    Many great plugins such as mcMMO do not approach it this way, They send SQL queries for everything that is done.
    For instance on my server this would result in about 300+ SQL queries a second. As a result, this plugin would account for about 50% of the total plugin lag that is produced because its so inefficient.

    Why did they approach it like this?
    Cuts the workload (development time) in about 1/2.

    Is there a benefit to this?
    Yes your data is always real time. Changes to the database will take immediate effect in game.
    If you only have 10 Players on your server. or you don't care about tick rate or lag then why not.

    SQL is great for the following reasons.

    With the right library, implementing functions like getting data, storing data and modifying data is very straight forward using SQL Queries which is very universal.

    Manipulating SQL Data from other applications (Such as a webpage) is very basic using php.

    If you every want to go in manually and modify the data you can access it very easily using a program like navicat.

    Using SQL queries is much more efficient then writing/grabbing data from a file. This is because you don't have to develop algorithms on the most efficient/fastest way to manipulate/read data from a file. SQL does all this for you and stores the data in Memory to increase read/write times 10-100x


    However when it comes down to it. The most important part about writing a plugin, is to understand when to manipulate data from SQL/File and when not to.


    There's no benefit to using a file system over SQL. However learning how to use SQL libraries in java takes some time. Also understanding how SQL works and learning the language to make queries takes time. Sometimes there's no practical advantage of using SQL (In cases where data is manipulated very few times) and you can use a file system instead.

    SQL is something all programmers should be familiar with. It is used in most programming languages to deal with data manipulation.
     
    migsthegod likes this.
  2. Offline

    Milkywayz

    Adding queries to a queue in java before being added to a database would be ideal correct? Well when a plugin is disabled all the contents in memory are wiped, so all those mcmmo queries would be gone. Unless you want to purge the queue into the database on disable which causes restarts to be slow and lag for that matter, it will be hard to do. Also if your not already aware, McMMO stores data in your world folder, so it uses both mysql and a file system. Also i prefer plugins to store via mysql since its generally faster, doesn't clutter my server folder, and is easy to view in phpmyadmin.
     
  3. Offline

    wow4201

    Not what I'm talking about at all. You pull all the SQL data to a hashmap when the plugin is enabled. You only change data inside the hashmap while the player is doing functions. Then when the player leaves you save the hashmap data for that player to the SQL database.

    SQL queries are not being queued.

    Some plugin developers use sql/file systems like their friggin hashmaps and it makes me RAGE! lol.
     
Thread Status:
Not open for further replies.

Share This Page