Author Topic: Found the reason why network play can be very slow  (Read 2930 times)

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Found the reason why network play can be very slow
« on: 31 March 2009, 01:33:42 »
I have recently been hacking away at the glest 3.2.1 code and fixed a bunch of network play items. Today I found out why numti-player network mode can get very slow and choppy... and I have a fix. The key problem (in my opinion) in the glest code is the fact that all the subsystems run in the content of only 1 thread. That means when multi-player network mode is enabled.. for every x frames of gameplay glest tries to process network messages (which can be VERY slow depending on your network configuration and response times of other clients). I did some tweaks and found that there are two sections of code that process network messages. I wrapped those two sections into pthreads so that the networking can run in parallel with the rest of glest.... and now when we play 4 player mode... nothing is choppy and all the commands are sent properly in the background. Even the server gets around 60fps!

I would call the current code that I have more or less a hack of the glest code as it was an attempt to understand what glest was doing and why 4 player network mode was so slow. If anyone is interested or has experienced this same issue perhaps we could work with the glest authors to add multi-threaded mode?

Thanks

wciow

  • Behemoth
  • *******
  • Posts: 968
    • View Profile
Re: Found the reason why network play can be very slow
« Reply #1 on: 31 March 2009, 13:32:48 »
Hmm, any chance you could post a patch for this?

Also Daniel.Santos is currently undertaking a re-write of the multiplayer system.

A long and detailed discussion can be found here:
https://forum.megaglest.org/index.php?topic=4015.0
Check out my new Goblin faction - https://forum.megaglest.org/index.php?topic=9658.0

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: Found the reason why network play can be very slow
« Reply #2 on: 31 March 2009, 15:07:24 »
I'm not sure how to make a patch as I never have done so before, perhaps someone could point me in the right direction? I run on Ubuntu 8.10 as my platform but have the option to dual boot into XP (which I haven't done in over 2 months now). Once I learn how to make a patch I'd be more than happy to post something.

Thanks

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: Found the reason why network play can be very slow
« Reply #3 on: 31 March 2009, 18:20:50 »
How to create a patch:
man patch
man diff

Or more easy, a little search with google gives this:
For example this should make it:
http://linux.byexamples.com/archives/163/how-to-create-patch-file-using-patch-and-diff/
especially this command:

diff -crB Tb01 Tb02 > Tb02.patch

Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: Found the reason why network play can be very slow
« Reply #4 on: 6 April 2009, 22:27:22 »
My original hack did not work. While the threading part worked nicely the game progresses on and eventually everything gets way out of synch for some reason. (I watch server and client on a 2 player game and over time things go their own direction). I'll need to understand the whole world / frames / networking parts before a real fix can be realized. I'll look at it when I can but I'm off vacation and back to work now so my time is more limited than the past week.

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: Found the reason why network play can be very slow
« Reply #5 on: 28 April 2009, 08:32:22 »
I think you have two parts in glests network code.
One part is where the clients send their commands to the server. I think this can be done in a separate thread without getting out of sync. But the part where the server sends the commands to the clients must be in the main thread. Otherwise the game will get out of sync.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios