Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help diagnosing lag on a TCP socket server


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 wildbunny   Members   -  Reputation: 550

Like
0Likes
Like

Posted 21 July 2012 - 11:00 AM

Hi guys,

So I have my little multi-player TCP game socket server running on a dedicated server on the web somewhere and I'm having issues with lag as the player numbers go up to the point where with 10 players I'm seeing 300ms ping times in game, making it unplayable.

Ping time is defined as the round trip time for an in-game message.

I'm struggling to diagnose the problem; the server side game loop itself doesn't slow down at all with 10 players, so I'm thinking it must be something to do with the socket server.

I'm running a c# sever in mono on a linux box. The game thread is separate from the socket server thread, messages are passed from the socket server into a queue on the game thread and all are guaranteed to be processed every frame.

* I've got NO_DELAY set on the socket connections made
* The messages received fit fine into the allotted buffer size I have
* I'm only doing around 100 send's per second on the server with 10 players
* I'm using the asynchronous socket functions BeginReceive(), BeginSend(), BeginAccept() etc...

Any advice about where to look would be greatly appreciated! :)

Cheers, Paul.

Sponsor:

#2 wildbunny   Members   -  Reputation: 550

Like
0Likes
Like

Posted 21 July 2012 - 11:14 AM

I should have said, normal ping times are 40ms-70ms with one player. And the average message size is <=1Kb.

#3 ApochPiQ   Moderators   -  Reputation: 15832

Like
0Likes
Like

Posted 21 July 2012 - 11:32 AM

Have you tried doing a packet capture to see where the slowdowns occur in the traffic stream?

#4 wildbunny   Members   -  Reputation: 550

Like
0Likes
Like

Posted 21 July 2012 - 05:59 PM

Have you tried doing a packet capture to see where the slowdowns occur in the traffic stream?


I haven't mostly because I'm not sure entirely how I would do that?

#5 wildbunny   Members   -  Reputation: 550

Like
0Likes
Like

Posted 22 July 2012 - 11:28 AM

Ok, turns out the lag was due to the use of the async socket functions. They seem to be very bad for highly (or even slightly) concurrent applications.

Ick. Looks like I now need to go find or build another socket server using the new SocketAsyncEventArgs which I'm only just discovering now... :|

#6 Madhed   Crossbones+   -  Reputation: 2995

Like
0Likes
Like

Posted 22 July 2012 - 12:17 PM

Have you tried using the Socket.Select method?

#7 wildbunny   Members   -  Reputation: 550

Like
0Likes
Like

Posted 23 July 2012 - 02:17 PM

For the sake of closure - the fault was mine.

By putting an 'infinite' loop inside the BeginAccept callback I was essentially hijacking the IO thread-pool's threads, depleting them to such a degree that they must have run out inside the BeginReceive() callback which would cause the lag.

I fixed this by relinquishing the callback threads as quickly as possible so they could be returned to the IO completion thread pool.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS