Tick offsetting!!

Discussion in 'Spigot Plugin Development' started by Jonnyo101, May 8, 2017.

  1. Hello i tried to explain this before but i was misunderstood i am wondering offsetting operations on a server would help performance.

    Let me give you a example. (Not real code just to explain)


    On the OnEnable
    CitizenSpawnManager.spawnTask();
    CitizenTargetManager.targetTist();
    CitizenCore.itemhandTask();
    CitizenActions.actionsTask();
    CitizenCorpse.timerTask();
    CitizenPathing.entityPathTask();
    CitizenPathing.pathWeightTask();


    All the method above all create a repeating task. And ALL tasks have a 20 tick delay.
    Its my understanding that they would all run at the same time.
    So they would run on tick 20, 40, 60....
    However this is processing everything in that one tick.
    Would adding offset like so

    In the OnEnable
    CitizenSpawnManager.spawnTask();
    #Add a 1 tick delay.
    CitizenTargetManager.targetTist();
    CitizenCore.itemhandTask();
    CitizenActions.actionsTask();
    CitizenCorpse.timerTask();

    #Add a 5 tick delay
    CitizenPathing.entityPathTask();
    CitizenPathing.pathWeightTask();



    So with the the above methods would all be a 20 tick repeated task but offset.

    So my understanding is that
    -Blue would run on ticks 20, 40, 60
    -Red would run on ticks 21, 41, 61
    -Green would run on ticks 25, 45, 65
    Spreading the load on the server.

    P.s This is for a VERY big stand alone plugin i am creating that has a lot of different things going on in the plugin i would not do this on a small plugin.
     
  2. I know that i am not asking how to delay a task. I am asking is offsetting the "Operations" on the server would help.
     
  3. Oh, well, most likely. It's always better to spread out heavy tasks rather than force them all at once. In any case, this is one of those "try it and see" type questions...
     
  4. Yes it would, defiantly. Hence why we have the, as @BillyGalbreath mentioned, parameter option to delay when each induvidual task should start occuring on intervals.

    However, if you have very heavy tasks, and some are not using methods from the Bukkit API, you might want to consider asyncronous handling (just make sure to stay thread safe) as I would imagine your main thread is being halted/struck quite a bit.

    EDIT: Punctation.
     
  5. yer i run the intensive stuff like pathfinder and stuff a seperate thread. i was just woundering is i sould offset all the little tasks. and yer i know about the bukkit tasks but i use my own i only said the bukkit as its know to most people.
     
  6. Whay? Couldn't that get a little bit tricky when co-running with minecraft's ticks?