1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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

Thoughts on Lag

Discussion in 'General Discussion' started by Nivlac_13, Jan 11, 2015.

  1. Nivlac_13

    Nivlac_13 Shopkeep Stealer

    Messages:
    115
    I got a new GPU recently and figured I'd monitor my temps while playing various games. It's a fairly straightforward process, game on one screen while temps and stats are shown on the other. My most GPU intensive game turned out to be Space Engineers in case anyone was wondering. Then I played KAG since I figured my days of playing with intense amounts of lag were over. Then I experience some of the worst lag I ever have on KAG while only utilizing 10% of my GPU. Investigating further I found that my CPU was pegged at around 25% when the lag was bad. Eventually I got the advice to reconnect, so I did. The CPU usage dropped to about 10% and the lag was gone. So now my thoughts. I'm guessing that KAG relies very heavily on the CPU for a lot of stuff. I'm also guessing that it only utilizes a single core, hence the 25% of my quad core CPU. Therefore lag could be mitigated in two ways. Either move processes to the GPU or utilize multiple cores. I'm sure this is much harder than it sounds because if it was easy it would already have happened. Or maybe I have a terrible CPU that bottlenecks my system.
    Specs:
    A8-6600k quad core @ 3.9 GHz
    Asus R9 270
    2 x 4gb 1866MHz
    A motherboard
    A case
    A PSU
    Some storage
    Note: I will edit this for clarity in the morning my writing isn't the best at 1 AM
     
    Hallic, Tern and norill like this.
  2. Shadowor

    Shadowor Shark Slayer

    Messages:
    184
    One of the reason I don't/can't play that much anymore. The fps drop is so terrible it breaks the game, and this issue is old. I think it's because of the blobs and all that stuff. Relogging seems to be the best solution, but it only gives you another 4 minute smooth gameplay. It is not your computer's fault, it's the game's.
     
    Hallic and DatNobby like this.
  3. KAG does rely very heavily on the CPU. It happens for me as well.
     
  4. wilpin7

    wilpin7 Lewd~ Donator
    1. KAG Competitive League

    Messages:
    153
    Same here, stopped playing after a while, probably gonna build myself a fresh and new PC this summer (when I'll possibly have the money for it?) for now I'm stuck stalking the forums.

    Not that I mind doing so.
     
  5. Nivlac_13

    Nivlac_13 Shopkeep Stealer

    Messages:
    115
    If relogging fixes lag then that implies that there is some process that gums up the CPU over time that could either be removed or reset every once in a while. Even something that reconnects everyone to the server every 30 minutes would be preferable to playing at slide show speed.
     
  6. Horse_That_Goes_Ni

    Horse_That_Goes_Ni Your favorite Persian Staff Alumni Donator

    Messages:
    233
    I noticed that a lot of my friends who had AMD cpu's told me they had a lot of lag in late games, or even early ones. I used to have a pc with an AMD cpu in it and I experienced the same problems. Not long ago, I got a new pc that had an intel quad core cpu in it and the problem was totally fixed for me. Im not saying that you would have to get an intel cpu, but to all my friends and I it feels like the game "favors them". My friend who has an intel pentium also says that he never experiences lag either.
     
    SirDangalang and FuzzyBlueBaron like this.
  7. Crabmaster

    Crabmaster Bison Rider
    1. Zen Laboratories

    Messages:
    322
    I sometimes wish there was a way I could be informed of the day this problem is finally fixed, because once it is I might properly return to this game and community and finally get to play full rounds again. (And there might be a larger player base, too, if that happens...)
     
  8. amgtree

    amgtree Ballista Bolt Thrower

    Messages:
    482
    I have an apu and I get around 250 fps
    btw my computer is one of those stock store bought ones
    [​IMG]
     
  9. hierbo

    hierbo Ballista Bolt Thrower
    1. The Young Blood Collective - [YB]

    Messages:
    190
    Unfortunately, I doubt this is just a bug. If it were, it would likely have been found by now. There are a ton of ways to solve any given individual problem in programming, but some of them are more efficient than others. In fact, one solution could be orders of magnitude more or less efficient than another, even though they essentially do the same thing.

    So, even though KAG is not a "big" looking game, there is likely some code in it that is written in one of these suboptimal ways, that either can't be found, or a better more efficient solution has not been devised.

    I don't mean to impugn the developers here. It is not always obvious that a piece of code could be written in a more efficient way. I hope they can figure it out, but I doubt its easy, any maybe not even feasible at this late stage. What @Geti and his team are working with now is somewhat analogous to a mechanic trying to work on a car while it is driving.
     
    Last edited: Jan 11, 2015
  10. i think lag is bad and we should remove it
     
    Havelock, Ozminer, Ricket and 9 others like this.
  11. Nivlac_13

    Nivlac_13 Shopkeep Stealer

    Messages:
    115
    Now I have now idea what I'm talking about but it seems to me that it would be possible to move a lot of the processes that don't effect the gameplay to another core. Things like particles and building collapses could be calculated by a second core without the need to communicate to the first core very much because they don't have a huge effect on gameplay. About the Intel vs AMD performance, I've always heard that Intel CPU's have much better single core performance compared to similar AMD CPU's this would further prove my theory that KAG only runs on one core and runs that core hard.
     
  12. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,578
    It isn't a theory, it's the truth. KAG (barely) uses a single core.
    Intel CPUs are better for KAG overall.
    So if you want to play kag intensively, look for a computer with a i3/i5/i7 (not a U version) and an nvidia/amd card, at least 4GB RAM would be enough.
     
    hierbo likes this.
  13. Geti

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

    Messages:
    3,730
    "barely" uses a single core while maxing it out, sure thing :^)

    KAG will run on more or less any GPU from like late 90s onwards, that's not the problem - as others have alluded to, it's taxing on the CPU mainly. This comes from 99% of the game being written in scripts (which take a lot more CPU power to run than equivalent native code) and the engine architecture being a performance nightmare. There's only so much we can do without rewriting the engine (not going to happen) and therefore a large part of the game. Large scale optimisations are therefore unlikely to happen, unfortunately, though there's a chance we'll at least improve the cache friendliness of some of the component updates in the coming months.

    However, your CPU is pretty quick. AMD do have problems with code being optimised towards intel CPUs - we believe microsoft's compiler does this automatically; newer versions have a way to optimise towards AMD CPUs but of course this would just put intel users in the same situation.

    Giving KAG priority over one core can help.

    More RAM won't help (it doesn't use more than a gig at a time worst case, unless you're on a server that's doing something funny), faster RAM might a bit, but not much.

    Re: "moving stuff to the GPU or threading it" - you're right that this is much harder than it sounds. You can't just say "ok run this bit here, that bit there, great now everything's faster" - most of the processing-heavy stuff KAG does is inherently serial (for example, scripts cannot be run at the same time without introducing race conditions, as they have access to the entire engine). The GPU is (in a general sense) a very simple, highly parallel computer. The stuff KAG does is very complicated (in an instruction set sense) and highly serial, which makes it unsuitable for processing on the GPU or in threads/across cores.

    If the engine was developed from the ground up with those in mind, it'd be a different story. It wasn't, so it's not.
     
  14. Nivlac_13

    Nivlac_13 Shopkeep Stealer

    Messages:
    115
    Interesting, I've never heard of a program optimized for Intel vs AMD CPU's. So the question I still feel is unanswered is why does the CPU bog down over time but gets "refreshed" when you reconnnect?
     
  15. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,578
    Intel graphic chipsets are more terrible than you'd think :p
    GMA ones are pretty horrible (I see people that can't even run Minecraft with it, or has 2-3 fps with a bad-normal CPU)
    Any "dedicated" graphic card will do, even low-end AMDs - you're right.

    By the way, an off-topic question - How do you compile to Linux and OS X using MSVC? Are you using different IDEs or have some script to compile that?

    What's threaded, also? iirc, someone told me networking was - That isn't the most resource demanding stuff, am I right? So it won't make a really large difference. I think that if you have 4 cores and the 2 first heavily used, it would be better to move KAG to the Core 3 and 4 - Or does Windows manage it automaticly?

    I also wasn't talking only about the game requirements - More about the overall usage. It's easy to get over 1GB RAM used after the computer started, to take 512Mb with custom programs, to get an browser opened (512Mb for firefox, maybe less), in that case, 2GB RAM is not really enough. Using the virtual memory will destroy the speed.

    I'm again being slightly off-topic, but, couldn't you let modders create their own threads? I think that would break when you use some functions from the KAG lib (until you adapt them for this), but it would allow advanced modders to optimize some complicated (or not) calculations.

    I think that's because something is being created but never destroyed until you leave the server you're currently on, and these would waste CPU every tick, and gets destroyed only on disconnect? I don't really know.
     
  16. hugio88

    hugio88 I am the king of KAG! Donator

    Messages:
    130
    I don't have any fps drops :)
     
  17. Geti

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

    Messages:
    3,730
    @AsuMagic - I'd encourage you to not talk too much about things you don't have a good understanding of :^)

    Re: GMA/Integrated Intel - I used to play on these, it's not so bad. KAG is an "openGL 2 spec" game, and very simple graphically. The CPU will be the bottleneck even with integrated graphics. With faster graphics mode I get 25fps+ for KAG (playable), it starts to chug when there's a lot going on but that's still CPU bound.

    Re: Threading and networking - unthreaded networking is generally a pain, as a lot of calls to read data from a connection are "blocking" ie they freeze the thread until there's data there. We actually use a library (ENet) to abstract the network away from us.

    Re: Threading in general - yes, it would be "good" to "move it to 3-4 cores" but as I explained in detail above you can't just DO that. Threading isn't some magic dust you spread on code to say "run this faster please" - it requires the logic of your program to have some level of data independency (which KAG does not have) to be able to run anything in parallel.

    Here's an image as I feel like you're not "getting" this:
    [​IMG]
    The brown tasks are dependent on one another. You can not run them out of order or along-side each other. In KAG, there are a lot of brown tasks.
    The blue tasks are not dependent on one another. They can be run whenever you like, even out of order. In KAG there are few blue tasks.
    As you can see, with a large number of brown tasks, even with 4 threads (or hundreds), there is not much speed-up. In fact, you lose performance because the computer has to do some work swapping between threads, and monitoring the increased number of threads that are mostly just sitting around doing no work.

    Work (often lots of it) needs to be done to convert any brown tasks to blue tasks, and then more work has to be done to actually make them execute in parallel (thread them).
    It is not a trivial thing to do at all, especially when starting from legacy code (as we are with KAG).

    Letting modders create their own threads is really really problematic as well - we'd need thread-safe ways of signalling various events, modders would have to understand the idea of data parallelism, race conditions and synchronisation, and we'd have to find some cross platform (and "easy") way of exposing that stuff to modders.

    I'm hammering this home as much as I can because I feel like there's a very big misconception around "threads". Grab a C++ compiler and try writing a threaded program, or try threading some previously unthreaded program. You won't have fun.


    Re: Having stuff open behind KAG - you're an idiot if you're complaining about FPS issues with anything meaningful open in the background, imho, especially ram hungry performance nightmares like web browsers.

    Not sure why it would happen, it's the one thing we can look into. Maybe things getting spread out in the netobject array or similar leading to cache coherency problems. Could just be plain heap fragmentation. Would need more diagnostics to really know.
     
    Asu likes this.