Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Discussion] GameServer Optimization

Newbie Spellweaver
Joined
Apr 21, 2014
Messages
22
Reaction score
1
So... After having some issues with player / zombie lag, which happened to be totally fixed, it happened due to players being downloading files from the same server - patcher, which is weird since I have this connection:

ThatGuyPT - [Discussion] GameServer Optimization - RaGEZONE Forums


But whatever, I moved the patcher to a seperate server. I now have been looking at the WZ_GameServer source code and soon I found a major performance flaw. I expected the performance to be balanced between all the functions existent in the code, but I stumbled into something. Disabling some paths of the source apparently made the game use 0% of the CPU, or very close to that, with 5 people there testing. Even though it is not properly broken, I mean chat works, you can move, you can kill each other (bugged though).


I found out that the object updating method is draining all the CPU power, not sure if it is a flaw in the way it is coded or anything else but thought I could share this with you so we can fix it together.

Please post any advances in this, remember you probably wouldn't know of this and think it was all OK if I didn't inform you all so inform all the community aswell in return.

Function: BOOL GameObject::Update()

Code:
BOOL GameObject::Update()
{
    // NOTE : IsSleeping perfomance is slow when scaled to 1000 objects,
    // that's why we use perma sleep flag ( most of these objects always sleep )
    if(
            !( ObjFlags & OBJFLAG_ForceSleep )
                &&
            PhysicsObject
                && 
            (!PhysicsObject->IsSleeping() || FirstUpdate) )
    {
        if(FirstUpdate != 0)
            --FirstUpdate;
        // physics object is not sleeping, so let's update our position to match physics, and update transform
        r3dVector physPos = PhysicsObject->GetPosition();

        // sometimes physics returns QNAN position, not sure why
        if( r3d_float_isFinite(physPos.x) && r3d_float_isFinite(physPos.y) && r3d_float_isFinite(physPos.z) )
        {
            if( ( vPos - physPos ).LengthSq() > 32 * FLT_EPSILON )
                ShadowExDirty = true ;

            vPos = physPos;

            D3DXMATRIX mat = PhysicsObject->GetRotation();
            mat.m[3][0] = 0.0f; mat.m[3][1] = 0.0f; mat.m[3][2] = 0.0f; mat.m[3][3] = 1.0f;
            r3dVector rot;
            MatrixGetYawPitchRoll ( mat, rot.x, rot.y, rot.z );
            NormalizeYPR ( rot );
            rot.x = R3D_RAD2DEG ( rot.x ); rot.y = R3D_RAD2DEG ( rot.y ); rot.z = R3D_RAD2DEG ( rot.z );
            if(!vRot.AlmostEqual(rot, 0.01f)) // do not change rotation if it didn't change
            {
                vRot = rot;
                ShadowExDirty = true ;
            }

            Velocity = PhysicsObject->GetVelocity();

            UpdateTransform();
        }
    }
    return TRUE;
}

Image as a proof of what I'm saying:
ThatGuyPT - [Discussion] GameServer Optimization - RaGEZONE Forums

ThatGuyPT - [Discussion] GameServer Optimization - RaGEZONE Forums



So yea, if anyone's interested this is all Zombies' AI.

Of course there isn't that much to be fixed but small optimizations can still be done.

Commenting Zombie's updating function out freezes CPU usage at 0% unless between time to time when it reaches 10% for 3 seconds (not sure what is it).

The function (method) you need to look for is BOOL obj_Zombie::Update()
 
Joined
Sep 27, 2006
Messages
557
Reaction score
88
Re: Found a major optimization flaw in the game server

Think we fixed ours to only use 5% for all cpu's even during 300+ people online. There are issues besides zombies.
 
Joined
Aug 14, 2009
Messages
2,304
Reaction score
1,189
Yep but if you comment zombie:update out your zombies are just standing there-

Better Idea (Didn't tested it)

Say for example you have 300 zombies. This update logic runs 300/s. Maybe you could make the ZombieSpawn a global zombie brain.
And switch the whole update logic from all zombies to this ZombieSpawn. Instead of updating 300/s it's 1/s BUT Idk how it does with massive updates. Because 1 object needs to update 300 zombies..
 
Newbie Spellweaver
Joined
Apr 21, 2014
Messages
22
Reaction score
1
Yup, but most of the time it stays at 0%, sometimes it peaks to 13% or something I haven't found out why yet.

If you comment the zombie update they do nothing you're right but I suppose there's a way to recode them to eat much less resources, jonnybravo did it apparently. Anyway I'm just sharing what I've found. I'm pretty sure this is a great found for most people.
 
Junior Spellweaver
Joined
Jan 21, 2013
Messages
158
Reaction score
53
Yep but if you comment zombie:update out your zombies are just standing there-

Better Idea (Didn't tested it)

Say for example you have 300 zombies. This update logic runs 300/s. Maybe you could make the ZombieSpawn a global zombie brain.
And switch the whole update logic from all zombies to this ZombieSpawn. Instead of updating 300/s it's 1/s BUT Idk how it does with massive updates. Because 1 object needs to update 300 zombies..

logic fail...

300 ai run 300 cycle / sec. <- this is the ai at the moment

implement global ai?

global ai is 1 object, but must run through 300 zombie to navigate them..
so 1/s but on 300 zombie so... on 1 sec must be update 300 zombie...
if not finished... server wait for finish... so no matters..

the update isnt the bad thing...

the worst code is inside the update..
every sec create a cycle to find the victim player for attack... zombies do this in every state... everytime...
and checking for barricade, checking distance to attack... etc. <- this is the main problem
 
Last edited:
Initiate Mage
Joined
Aug 10, 2014
Messages
2
Reaction score
0
Better to create a parallel thread where zombie AI runs.

The secret here is... players will feel the game run smooth because zombie AI wont take time from game loop (unless there's an update from zombie AI thread).

Same technique can be used for loot updates (loot expiration/spawn).
 
Back
Top