Solved Whats more efficient?

Discussion in 'Plugin Development' started by CreeperShift, Mar 27, 2013.

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

    CreeperShift

    Alright so I have 2 races where people can join. Now the question is, which way is more efficient:

    1. I already have a MySQL database for other stuff, so store a players race in there any retrieve it everything something happens (aka. checks in which race he is)

    or

    2. Use the mysql database only for storage, put his race into a hashmap or something when he logs in (after checking with the database) and removing it when he logs out. So it only has to check the hashmap for players.

    Is the first way significantly slower? Because the second way would pretty much mean a bit of additional code and I'm lazy :p
     
  2. Offline

    Technius

    Write both of them and benchmark both of them!
     
  3. Offline

    CreeperShift

    ._. you missed the last 3 words :))))))))

    I'm just curious if continuous MySQL queries are a bad idea, I'm really a noob with mysql so idk
     
  4. Offline

    Technius

    Then I can't really help you here.
     
  5. The first way is hella-bad, your gonna in essence stop the main thread (you know, the one that handles AI, chunks, network packets etc) while a call is made across the network to an sql server (something that's pretty slow in cpu terms).

    Load when they join so you only hit the db once, and lazily remove it once they're gone using a scheduler (this stops db hits if a user has connection problems and consistently connects/reconnects) that periodically runs to clean up the hashmap (say, once every 5 mins)
     
    CreeperShift likes this.
  6. Offline

    iZanax

    I don't got a lot of experience with MySql, but what u can do is,

    * Run at Player Login/Logout a Query
    * Queue all Queries (store them in a variable) and run them every x minutes (after that, empty them)





    # All querries should be runned Async and Bukkit API calls Sync, so its a bit messy but it's really needed to have no freezes.
     
  7. Offline

    CreeperShift

    I was afraid something like that would happen :O
    Wasn't sure how fast/efficient Mysql is.

    Thanks for clearing that up, I'll take the 2nd way then :)

    tehbeard

    If you don't mind me asking, I just read that I should be using MetaData instead of Hashmaps for players, is that true?
    I'm not entirely sure how metadata works, but would it save me the trouble of clearing out the hashmap when they log out? Or Would I still have to somehow clear their metadata?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page