1.8.8 Concurrency help!

Discussion in 'Spigot Plugin Development' started by yiatzz, Jul 15, 2021.

Thread Status:
Not open for further replies.
  1. Hi! i'm developing a plugin where i need to load data from SQL and cache it on a in-memory cache.

    My current logic is:

    On player join -> fetch data from mysql (in the async player pre login event) -> sync cache it on the in-memory cache -> save to the mysql whenever the object is changed (async) -> remove from the in-memory cache when player leaves.

    Screenshot_3.png

    Screenshot_2.png

    My doubt:

    Is it good? My server's player base right now is abot 300-350 players. I was having some CPU issues when many players joining at the same time the cpu usage goes up 80%.

    Hope u guys can help me :)
     

    Attached Files:

  2. In principle it makes sense but it depends on a few things, ie. how often you update and object. If it happens very frequently, you might want to wait and send many updates in bulk depending on their nature.

    Also, are you using a connection pool like Hikari CP?

    // Edit
    Watch your static abuse.
     
  3. Yes, i'm using a hikari cp pool.

    About the update frequency imagine like 10 updates per second
     
  4. Update periodically like every 30 minutes instead.
     
  5. where?
     
  6. SkillsProvider and TaskManager are clear examples.
     
  7. lol you didn't see these classes' codes - so you can't say throw "static abuse" and certainly not "clear examples".
     
  8. Italic fonts are used for static members. TaskManager and SkillsProvider should be instantiated to objects and their methods be made non-static. If SkillsProvider.Cache is a static subclass, even more static abuse.
     
  9. it follows the SOLID pattern so its not a static abuse.
     
    • Optimistic Optimistic x 1
  10. The flow you've described makes sense and I would do it the same way. Load and cache (blocking) during pre login and save whenever your data changes.

    I often see people saying that you should save when a player leaves or using an interval. I personally don't like that aproach as it's less reliable. If your server crashes you lose all unsaved data. If another application reads from your database it will use an outdated value, which can cause bugs.

    Databases can handle a lot of load, so its perfectly fine to instantly write your data. Its often better to perform a lot of small tasks than to perform a few large ones. That said, cache is important to make to make your read operations faster, but I wouldn't delay your save operations by more than a few seconds.
     
  11. As I said, you have no idea what goes behind the interface - so you can't say it's static abuse.
    Maybe singleton makes sense here? Maybe they're cached instances? Maybe he thought a static class named "Repositories" is more comfortable for him?
    You have no idea.
     
  12. The SOLID principles* are not related to static, static is an implementation detail while SOLID are abstract concepts.
    The way you talk hints to me you most likely are abusing static...
     
    #12 HorrendousEntity, Jul 16, 2021
    Last edited: Jul 16, 2021
  13. Singletons are fine, I can see SkillsPlugin is a singleton and in fact I never said anything about that (read previous posts).

    Also, I never said anything about Repositories, not sure why you put words in my mouth
     
Thread Status:
Not open for further replies.