Sign in to follow this  

Help diagnosing lag on a TCP socket server

This topic is 1973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1342891966' post='4961714']
Have you tried doing a packet capture to see where the slowdowns occur in the traffic stream?
[/quote]

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

Share this post


Link to post
Share on other sites
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... :|

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 1973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this