How long would you say to class a method as lagging ?

Discussion in 'Spigot Plugin Development' started by Jonnyo101, Jul 22, 2019.

  1. Hello i am doing a question system where other developers can add there own quest elements to the plugin.
    In there elements there is a checkElement method that when returns true shows that element has been finished.
    This method is a method that is repeatedly called

    Where this method is called i am timing that method using systime like

    long t1 = System.currentTimeMillis();
    METHOD CALL
    long t2 = System.currentTimeMillis();
    if (t2 - t1 > 100)

    What value would you put to give the conclusion that the element is a laggy one and should be looked at ?
     
  2. Consider the method laggy when it causes the TPS to decrease significantly.
     
  3. i am not looking at the tps drop by that time the server is already lagging lol.

    If a developed makes a questing element and it take 5s(over kill) to do the update check i will know that that needs to be looked at.
    I am adding this to try and detect lag before it shows

    So i am asking, how long would you say is to long for a repeating method to execute
     
  4. drives_a_ford

    Moderator

    Whenever you check the time that a method took to run, if it took more than 50ms, you've got a problem.

    However, what you're trying to do really seems like micro optimization where I'm not sure it's needed. If someone else's plugin (i.e an addon to your plugin) is causing performance issues, it's their problem not yours.

    EDIT:
    There are tools (i.e timings) to detect which plugin is causing issues. If a server owner is experiencing issues, they're welcome to use those tools to figure out which plugin is causing the performance loss and act accordingly.
     
  5. Benz56

    Moderator Supporter

    That really depends, but as @drives_a_ford mentioned you're probably trying to micro optimize. If you expect a method to be blocking for an extended period of time (i.e. it is noticeable on the server) then run it async and make use of callbacks if you have to return something; e.g. by adding a Consumer as a parameter and accept the result in a sync task (simple solution).

    I know that my answer isn't exactly what you're looking for, however, it is a difficult question that is based on a ton of factors.
     
  6. I am not doing this for micro optimization at all.
    On the server we have 3 devs working on this question system adding there only things some of these devs are well lets say beginner.
    I am adding this to detect if they add in a element that's a obv lag source. So i can say to they you need to make it less expensive or rethink how you are doing it.
    EG a dev adds a element that keep looking over 5000 blocks every update (Every 5 ticks)
    I am looking to put in a number that is a obv flag up number


    Its so i will get a message like this
    [09:37:35 INFO]: Warning Long Element Time [Took: 1000MS] [Threshold: 75ms] [Creator: Jimbob][Element Name: ClientSide_ArmorStandEntity_PathToLocation]
     
  7. Benz56

    Moderator Supporter

    No more than a few ms then. I just tried timing some parts of my GPS plugin. I timed the starting of the GPS which includes canceling the currently running GPS, creation of the new GPS, spawning entities, resolving the shortest path through 10 points (over 100 configured) in my testing, distance calculations for the bossbar tracker, start checks and more. That took sub 1ms on average and that includes multiple method calls. (Measured with nanoTime)
     
  8. Okay thank you i will use 5ms
     
  9. You need to measure some methods yourself, because its highly dependent on computing power and other factors