Author Topic: .NET Socket performance  (Read 3105 times)

unmaker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
.NET Socket performance
« on: June 02, 2015, 03:38:53 AM »
Hello everyone,

I am creating a deterministic lock-step server for my mobile App. All my server does is take requests from players and sends it to all other players connected in the same room. No game logic on server or anything.

While determining how many players my server can handle by benchmarking some areas of the server. I found something that is really disappointing..
 
It turns out that it is really expensive to send a packet. On my server that is running on DigitalOcean, sending one packet takes a whooping 1600 ticks! this seems incredibly expensive.

I thought it may be because of running the server on Linux through mono. So I tried benchmarking on my windows.  It takes roughly 800 ticks to send just one packet.. That is still expensive if you are planning to have the few hundred players on one server.

For example, if it takes 1600 tick to send a packet and you send a packet 30 times a second(which means sending a packet every 33.33 milliseconds) If you do the math: 33.33 milliseconds = 333300 ticks. 333300/1600 = 208.That means you can only have about 200 players connected at the same time if you want to make sure to send an update every 33.33 milliseconds.

This is a little disappointing for server that all it does is relay the packets among all other players.

I wondering if you guys can help me by posting how many ticks it takes to send a packet on your server. You can easily check using C# stopwatch. for example this is how i benchmark mined.

  1.  
  2.  
  3. long start = System.Diagnostics.Stopwatch.GetTimestamp();
  4.  
  5.    // If it's the first datagram, begin the sending process
  6.                     mSocket.BeginSendTo(buffer.buffer, buffer.position, buffer.size,
  7.                         SocketFlags.None, ip, OnSend, null);
  8.  
  9. Console.WriteLine("Send time: " + (System.Diagnostics.Stopwatch.GetTimestamp() - start));
  10.  
  11.  

 Also please state what kind of server and providing you have.

Thank you every much for reading this
 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: .NET Socket performance
« Reply #1 on: June 07, 2015, 01:01:50 PM »
I don't think you understand what "ticks" are. A tick depends on your hardware and CPU clock speed.

I had a Windward server with over 300 people on it running on my home computer in the debugger, using roughly 5% of the CPU.

unmaker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: .NET Socket performance
« Reply #2 on: June 27, 2015, 10:57:08 PM »
Yes, you are absolutely right. Thanks for clarifying.

I assumed ticks are constant(about 10 nano seconds), but turns out they have different meanings on different machines.

After properly measuring the speed using Stopwatch.Elapsed.TotalMilliseconds, sending packets is pretty inexpensive =)