Solved Lag Issue and Timings Report question.

Discussion in 'Plugin Development' started by Dippoakabob, Aug 22, 2013.

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

    Dippoakabob

    I've been having some lag issues on my server thanks to a plugin that I've been working on. I've managed to narrow the lag down, thanks to the timings report. After running my server for about a day I ran the timings report command and I found that my plugin was causing roughly 2000 seconds of lag :confused: I looked through and found this line in the report.
    Code:
    EntityDamageByEntityEvent (and others) Time: 1980739768000 Count: 219487 Avg: 9024405
    This is the main cause of the lag.
    My question is what events are encompassed in the "EntityDamageByEntityEvent (and others)" event. Because my plugin only calls the 'EntityDamagedByEntityEvent' 4 times but there are 9 "EntityDamageByEntityEvent (and others)" events in the timings report.
    If anyone can let me know what events I should be looking under to find the issue that'd be great :)
    Also, I've already looked under all the "EntityDamageByEntityEvent"s with no avail. I just need to know what the " (and others)" part means :)

    If anymore info is needed please just ask and I'll make sure to add it.
     
  2. Offline

    metalhedd


    This report is based on time spent handling the events. when you say your plugin only 'calls' that event 4 times what do you mean by that? because you generally don't need to ever 'call' that event (using getServer().getPluginManager().callEvent()). you would only define a handler for it

    @EventHandler
    public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { // handler code here }

    and even then, having 4 handlers like this seems excessive... so what are you trying to accomplish, and what do you mean by 'calling' the event? because if you're ACTUALLY calling that event 4 times, that's probably the entire problem.. you shouldn't call it at all.
     
  3. Offline

    Dippoakabob

    By call I meant that I was using that event:
    IE:
    Code:
    @EventHandler
    public void onDamage(EntityDamageEntityEvent event){
        //some stuff here
    }
    It's a rather large plugin.
     
  4. Offline

    DrTURTLE2

    Dippoakabob Off topic but is this for your melon project? :D
     
  5. Offline

    Dippoakabob

    This is what I mean in the Timings report By the way, this is what it shows for the DamageEvents:
    Code:
        EntityDamageByEntityEvent (and others) Time: 501477000 Count: 219487 Avg: 2284
        EntityDamageByEntityEvent (and others) Time: 343863000 Count: 219487 Avg: 1566
        EntityDamageByEntityEvent (and others) Time: 14911081000 Count: 219487 Avg: 67936
        EntityDamageByEntityEvent (and others) Time: 6864186000 Count: 219487 Avg: 31273
        EntityDamageByEntityEvent (and others) Time: 790445000 Count: 219487 Avg: 3601
        EntityDamageByEntityEvent (and others) Time: 526982000 Count: 219487 Avg: 2400
        EntityDamageByEntityEvent (and others) Time: 458136000 Count: 219487 Avg: 2087
        EntityDamageByEntityEvent (and others) Time: 1980739768000 Count: 219487 Avg: 9024405
        EntityDamageByEntityEvent (and others) Time: 1056556000 Count: 219487 Avg: 4813
    I don't get why there are so many events under this section, seeing as I only use the EntityDamageByEntityEvent 4 times. Also in the report, this event is the only event followed by the " (and others)"
     
  6. Offline

    metalhedd

    if its really necessary to have 4 of them, you should be aware that every time damage is done by an entity, you're calling 4 methods instead of 1, you should attempt to minimize that and bail early as much as possible.

    As for your actual question. I'm not entirely sure, to be honest, but I think the 'and others' means subclasses of EntityDamageByEntityEvent, which IIRC, there actually aren't any... so I'm probably wrong on that...

    still though, I dont think it's going to lead you in the direction of solving your lag problem... your report is showing a very large avg time spent processing that event... so it seems that whatever you're doing in those 4 handlers is far too much.
     
  7. Offline

    Dippoakabob

    Yes, it's for my MelonKits.com server. I'll update my signature in a sec because it's out of date xD

    Anyways: back to the topic on hand.

    In the damage events I do things like process the amount of damage to keep track of the damages that each player does so that I can then distribute the necessary amount of credits to each player for their percentage of damage done. I had previously been adding the damage that each player did to a multi-dimensional HashMap, but to try and figure out the lag issue, I disabled this feature. the HashMaps didn't seem to be the issue. I have since gone through each method where I used the EntityDamageByEntityEvent and nothing seems to be too big of an issue. The only one that may be causing lag is the event where I nurfed the amount of damage that a player did if they have strength. This is what that event has:
    Code:
    public void onStrengthHit(EntityDamageByEntityEvent event){
            if(event.getDamager() instanceof Player){
                Player damager = (Player) event.getDamager();
     
                if(damager.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE)){
                    Iterator<PotionEffect> effect = damager.getActivePotionEffects().iterator();
                    while(effect.hasNext()){
                        PotionEffect pe = effect.next();
                        if(pe.getType().equals(PotionEffectType.INCREASE_DAMAGE)){
                            double origDamage = event.getDamage()/(1.3*(pe.getAmplifier()+1)+1);
                            event.setDamage(origDamage+(origDamage*(.75*(pe.getAmplifier()+1))));
                        }
                    }
                }
            }
        }
    I will see if changing the way that I handle the iterator makes any difference.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    Dippoakabob

    Didn't change anything. There's still a lot of lag when there are 10+ people on. (My server should be able to hold 150, so that's a big deal) Something that's in the code is causing problems, but I've made sure to not have anything saving to file or grabbing from file in all of the EntityDamagedByEntityEvents. Anyone else know anything that I should try?
     
  9. Offline

    blablubbabc

    Dippoakabob

    As this event handler above doesn't seem to explain the lag which you are experiencing, it is probably caused by another of your event handlers then..
     
Thread Status:
Not open for further replies.

Share This Page