Question on MySQL and how to prevent overloading it

Discussion in 'Plugin Development' started by Lammazz, Mar 29, 2015.

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

    Lammazz

    (I'm probably going to be very hard to understand during this post, just ask if you don't understand anything)
    So I've been working on a server for a few months and it uses a lot of of MySQL. At the minute I'm not having any errors but a few months ago I was talking with another developer that was going to be working on the server with me and while speaking with him he mentioned some things about how if you're not careful you can overload the Bukkit thread with MySQL, I meant to look into it sooner but I suppose it's better late than never. I think he said basically the way to prevent it is to have a kind of list of things for the database to work through rather than any time the plugin wants to use the database it just forces it to get or set whatever it wants. So kind of make it so for example the database is limited to 25 queries per second as oppose to there being times where there is only 5 queries per second then very short periods where there the database is being worked (Player joining/leaving). A way that I am already preventing strain on the database is having things like balance (all custom) stored in a map of player name and balance that is only ever edited when a player joins, leaves or a player's balance is edited rather than having to update it on the database when doing something simple like adding 1 coin for killing a mob.

    I believe Hypixel do something like what I'm looking for, when you join any of the lobby servers and open your profile (Own head on hotbar) and hover over your guild information or character information quickly it will say "Loading..." for a second or two while it loads. I of course can't be sure if that's what they're doing but I think it is.

    A lot of text, I've already looked around but haven't found anything on the subject. Like I said just ask if you need me to explain something better. Thanks
     
  2. Offline

    mythbusterma

    @Lammazz

    It basically comes down to this: Don't perform SQL queries on the main thread.

    Also, you should store data you're using in some sort of structure, instead of always requesting it from the SQL server, it will make your life much easier.
     
  3. Offline

    Lammazz

    I don't really know what you mean by don't perform SQL queries on the main thread. I'm already storing data from the SQL server rather than always requesting it, which I have stated... if you have even read past the title of my post :/
     
  4. Offline

    mythbusterma

    @Lammazz

    I was saying that as an addendum, I read what you said and answered your question.

    Don't perform queries on the server's main thread, that's all you need to do.
     
  5. Offline

    Lammazz

    @mythbusterma

    I don't really know how Bukkit threads work. How would I be running a query on the server's main thread and how would I not do that.
     
  6. Offline

    RainoBoy97

    You would run it on another thread.
     
Thread Status:
Not open for further replies.

Share This Page