Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Discussion Why PocketMine-MP uses synchronized event processing?

Comments in 'General Discussion' started by ns827, Apr 4, 2015.

  1. ns827
    Offline

    ns827 New Member

    Joined:
    Aug 24, 2013
    Posts:
    4
    Minecraft User:
    scalar77
    My programming skills are't that nice, but I have a question (and short opinion, maybe wrong.) about code flows of PocketMine-MP.

    - The Question: Why PM uses 'synchronized' event processing?
    I might be complicated with ideas of '(a)synchronized programming', but I've meant PM executes registered event hook in 'main thread' and blocks other code to executed on the thread. Yes, it could be called 'async' because PM ticks 20 times per second and does (almost) everything on main thread (I didn't forget about Raklib and map generator thread :p), but that's all. If tick processing delays about hooked events by plugin(like searching player data from yaml file, contains 15,000 all players' data), it could 'consume' ticks and then, PM will be laggy and print warning about low TPS. I was thinking about why developers of PM chose this method to process events, and I couldn't understand until now. (Yeah, I thought about starting new thread to execute event hooks could make performance issue on low-performance devices. PM is already heavy, I think.)

    - Opinion: Process Tick without '0.05 secs check', just ignore $this-> nextTick.
    My opinion is just ignoring $nextTick about tick delay, and run all jobs, like checking '\Threaded' packet stacks from Raklib thread, calculate player moving speed, executing user plugins. And for backwards compatibility, PM will run and time scheduled task one time per 0.05 secs (like old way).
  2. ns827
    Offline

    ns827 New Member

    Joined:
    Aug 24, 2013
    Posts:
    4
    Minecraft User:
    scalar77
    And this 'tick delay' frequently happens when you install A LOT of plugins, because PM tries to execute 25+ functions for one hook in 50 micro seconds
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can start an AsyncTask to handle your events. Things are run on main thread to let developers (especially new plugin developers) avoid race conditions more easily.
    Falk likes this.

Share This Page

Advertisement