Thread: cpu lag
View Single Post
  #4  
Old 07-12-2009, 06:16 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Is this for SoA? Just curious, because I got a PM on my forums about a similar issue with them, and I don't want to work the same issue from here and through PM at the same time.

What revision of source is the server running? A while back, there was a few versions put up that had a particularly nasty loop in the code that was driving CPU utilization way up. Also, have you tried checking the logs to see if this might be something related to a quest script gone wrong?

Check the following function in Hatelist.cpp and verify that the iterator.Advance(); in red is in your source:

Code:
Mob *HateList::GetTop(Mob *center)
{
        _ZP(HateList_GetTop);
        Mob* top = NULL;
        sint32 hate = -1;
        
        if (RuleB(Aggro,SmartAggroList)){
                Mob* topClientInRange = NULL;
                sint32 hateClientInRange = -1;
                LinkedListIterator<tHateEntry*> iterator(list);
                iterator.Reset();
                while(iterator.MoreElements())
                {
                tHateEntry *cur = iterator.GetData();
                        sint16 aggroMod = 0;

                        if(!cur){
                                iterator.Advance();
                                continue;
                        }                       

                        if(!cur->ent){
                                iterator.Advance();
                                continue;
                        }

                        if(cur->ent->DivineAura() || cur->ent->IsMezzed()){
                                if(hate == -1)
                                {
                                        top = cur->ent;
                                        hate = 0;
                                }
                                iterator.Advance();
                                continue;
                        }

                        sint32 currentHate = cur->hate;

                        if(cur->ent->IsClient()){
                                
                                if(cur->ent->CastToClient()->IsSitting()){
                                        aggroMod += RuleI(Aggro, SittingAggroMod);
                                }

                                if(center){
                                        if(center->GetTarget() == cur->ent)
                                                aggroMod += RuleI(Aggro, CurrentTargetAggroMod);
                                        if(RuleI(Aggro, MeleeRangeAggroMod) != 0)
                                        {
                                                if(center->CombatRange(cur->ent)){
                                                        aggroMod += RuleI(Aggro, MeleeRangeAggroMod);

                                                        if(currentHate > hateClientInRange || cur->bFrenzy){
                                                                hateClientInRange = currentHate;
                                                                topClientInRange = cur->ent;
                                                        }
                                                }
                                        }
                                }

                        }
                        else{
                                if(center){
                                        if(center->GetTarget() == cur->ent)
                                                aggroMod += RuleI(Aggro, CurrentTargetAggroMod);
                                        if(RuleI(Aggro, MeleeRangeAggroMod) != 0)
                                        {
                                                if(center->CombatRange(cur->ent)){
                                                        aggroMod += RuleI(Aggro, MeleeRangeAggroMod);
                                                }
                                        }
                                }
                        }

                        if(cur->ent->GetMaxHP() != 0 && ((cur->ent->GetHP()*100/cur->ent->GetMaxHP()) < 20)){
                                aggroMod += RuleI(Aggro, CriticallyWoundedAggroMod);
                        }

                        if(aggroMod){
                                currentHate += (currentHate * aggroMod / 100);
                        }

                        if(currentHate > hate || cur->bFrenzy){
                                hate = currentHate;
                                top = cur->ent;
                        }

                        iterator.Advance();
                }

                if(topClientInRange != NULL && top != NULL && !top->IsClient())
                        return topClientInRange;
                else
                        return top;
        }
        else{
                LinkedListIterator<tHateEntry*> iterator(list);
                iterator.Reset();
                while(iterator.MoreElements())
                {
                tHateEntry *cur = iterator.GetData();
                        if(cur->ent != NULL && ((cur->hate > hate) || cur->bFrenzy ))
                        {
                                top = cur->ent;
                                hate = cur->hate;
                        }
                        iterator.Advance();
                }
                return top;
        }
}
This was fixed in R472, and was introduced in R458. So, if your server is running code between those 2 revisions, either try updating and see if it fixes it, or simple adding the iterator as shown in red above should fix it.

I am not aware of any other bugs causing high CPU utilization recently.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote