1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

KAG Why does KAG eats so much CPU?

Discussion in 'Server Help' started by Asu, Feb 11, 2014.

  1. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Hey, I just don't know why KAG eats so much CPU on Fun CTF.
    It eats always around 100% when there is ~20 players and big map, and 20% when few people on normal map.
    I have a quite good machine though... My VPS runs with 6 cores ( 2.4Ghz ) and 8GB of RAM.
    Maybe a bug?
     
  2. Downburst

    Downburst Mindblown Global Moderator Forum Moderator Donator Tester

    Messages:
    1,813
    KAG can only use one core, so a server is bad if it has 6 weak cores.
     
    MelMinaya likes this.
  3. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Then why is CPU usage at 100%? Wouldn't it be around 100/6 instead?
     
  4. Leo

    Leo Haxor

    Messages:
    503
    kag is not multi thread as Downburst said. This means that each server can only use one core at a time. 2.4 Ghz is not enough it seems. My server has 12 cores each 3.4 Ghz and when it's full it eats 50% of a core now that I took slots down to 24. With 28 slots it eats 70-75% of a core and at map change it can go to 90%...
     
  5. Downburst

    Downburst Mindblown Global Moderator Forum Moderator Donator Tester

    Messages:
    1,813
    It uses 100% of 1 core.
     
    MelMinaya likes this.
  6. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    couldn't be multi-thread added for kag?
     
  7. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    No. I can (unfortunately) fairly confidently say that KAG will never be extensively multithreaded.

    Rewriting code that has been designed to run in serial (ie not multithreaded) in a parallel way (ie multithreaded) is a nightmare. If the engine had been programmed with multithreading in mind, then sure, but threading isn't some pixie dust you throw at the code and it suddenly runs three times as fast; it opens you up to a whole new subset of possible bugs which are much harder to debug, and getting code running portably is harder. Unless the threading is ubiquitous and well planned, it's also not often much faster, as a lot more time is spent checking locks, switching contexts, waiting on other threads to finish, etc.

    The only thing that's currently threaded in KAG is the API code. Incidentally, the API code has been identified as a likely candidate for the recent "every server lags" issue. Read into that what you will :^)
     
    FuzzyBlueBaron, lavalord and Asu like this.
  8. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Sooo is there a way to fix my overload issue, or at least to reduce it? Is there a way to optimize mono-thread apps to multi-cores? I'd bet it's almost impossible though..
    I'll try disabling compression and enabling fast deltas but I don't think it will improve a lot the problem.
     
  9. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    I would not do either of those things - disabling compression will mean your network usage will be up to five times as high, fast deltas is legacy functionality that will both expand usage and may result in crashing.

    Possible CPU Savers:

    Decrease your player count
    Host smaller maps
    Host maps without water
    Host gamemodes without siege
    Host gamemodes without explosives
    Decrease the amount of "scenery" blobs on your map (bushes, fish, trees) as this will reduce the amount of work box2d has to do


    Incidentally, You can host a heap of separate kag servers on a multi-core box without them affecting each other's performance.

    Hardmode:
    Write a gamemode that passes people between several hosted, unlisted servers ("realms"), which would all run separate maps. You can do this by getting them to evoke CNet::Connect with an IP and port from the listed "master" server, and when going through "portals" or off the edge of the map, or however you want them to move around. This would both alleviate your overloading-one-core issue and make your server very unique :^)

    Re: Is it possible to "optimise" to run on multiple cores -
    No, running on multiple cores at the same time is what multithreading is. It is possible for us to optimise how the game runs on one core, but you'd be surprised how much of that we've already done. Most of the CPU usage currently comes from libraries (angelscript and box2d, sometimes irrklang but not on the server) which are much harder for us to optimise (we have to rewrite other people's code rather than our own). It's not likely for us to do much of that other than fixing the current "omg server lags forever" bug which is being investigated this week.
     
    Nyarll, zerd, Noburu and 2 others like this.
  10. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Alsoo forgot to say all week when you're talking of server lag issue are you talking of ping, client fps or server tps?
     
  11. Downburst

    Downburst Mindblown Global Moderator Forum Moderator Donator Tester

    Messages:
    1,813
    Server lag can cause multiple different problems. Bombs exploding too late, people respawning too late, ping spikes, kicking everyone on mapchange, etc.
     
  12. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Oh that's exactly my problem. I have it often so if you need to test it on my server @Geti @MM, I can create you a linux account on my VPS for it.
     
  13. SnIcKeRs

    SnIcKeRs Bison Rider

    Messages:
    148
    Stop use hosts with OpenVZ xD
     
    Last edited: Feb 19, 2014
  14. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Someone told me performance lost is about 3%..
     
  15. SnIcKeRs

    SnIcKeRs Bison Rider

    Messages:
    148
    sometimes its 99%. Google OpenVZ virtualization
     
  16. Downburst

    Downburst Mindblown Global Moderator Forum Moderator Donator Tester

    Messages:
    1,813
    Just make sure your server never gets stuck on 100% cpu load....
     
  17. Nyarll

    Nyarll Catapult Fodder

    Messages:
    7
    Ok. Let's try!
     
    franek123 likes this.