Search Unity

[Solved] Server Load

Discussion in 'Connected Games' started by WiseGuy, Sep 2, 2009.

  1. WiseGuy

    WiseGuy

    Joined:
    Mar 1, 2009
    Posts:
    33
    Hey all

    Ive recently made a dedicated server for my game (empty scene with the server script). all that is being executed is the initial Network.InitializeServer(..) function and all that gets looped is the GUI.

    My question is this:
    Im seeing a 40% - 50% CPU usage on both my cores.
    Is this normal ? , if so .. why ?
    Is there a way to lower usage ?
    and how mush is it going to increase with incoming connections.

    Thanks
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    978
  3. WiseGuy

    WiseGuy

    Joined:
    Mar 1, 2009
    Posts:
    33
    Its on Mac

    my camera isnt even rendering (disabled, no Framerate) just a GUI on a very odd looking (640x480) frame.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    you can hook in the performance analyze tools and profiling and you will see what eats the time.

    My guess goes towards: a large amount is eaten by graphics and sound.


    Also, with a single gui in place, you actually have a full 3D scene.
     
  5. WiseGuy

    WiseGuy

    Joined:
    Mar 1, 2009
    Posts:
    33
    Im starting to assume that 40-50% isnt normal ???
    can anyone tell me this for a fact ?

    Ok, full 3D scene but no audio sources or draw Calls, not a single poly...

    im thinking that this seems like a infLoop but, not in my code, i looked. but surely the Network Server function uses a lite thread with a decent wait so it cant be that, can it ?

    Can the OnGUI() function be slowed down ?
    To do like 5 Draws a second or something ?
     
  6. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    978
    No, i saw earlier posts of jashan were he reported the same problem: The game will just fill up the CPU to get an as high possible framerate. Therefore you need to limit your framerate. There was a very easy trick for this...

    Edit:
    See the last post here: http://forum.unity3d.com/viewtopic.php?t=17700&highlight=fps+cpu
     
  7. WiseGuy

    WiseGuy

    Joined:
    Mar 1, 2009
    Posts:
    33
    [Solved]

    So this is what happened:

    Because there was noting taxing in my scene i was getting a frame rate of 800+. This caused the GUI to be drawn 800+ times a second, which gave me a 50% CPU usage. After using a sleep

    Code (csharp):
    1. System.Threading.Thread.Sleep(1000/capFps);
    at capFps = 12 I was using 5% CPU.

    Thanks Guys.
     
  8. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,088
    Hehe, yeah - I really liked the server framerates of 1000+ on my server, too ;-)

    I think Unity 2.5 introduced a new feature that allows you capping the framerate. I'd assume that the Sleep(...) approach does essentially the same, but it might be nicer to use that new feature.

    ... which is called ... um ... there we go:

    From: UNITY: What's New in Unity 2.5

    Ah, and here's the API documentation