RTC Forums
November 21, 2024, 04:57:10 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Resolving Network Congestion issues  (Read 18032 times)
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« on: January 12, 2018, 11:12:16 AM »

If your Server is frequently under high load, you are eventually going to run into problems caused by Network Congestion. If you are unfamiliar with the term, check this Wikipedia entry about Network Congestion. To fix this problem, you should reduce the size of receiving and/or sending buffers on the Server, before starting the Server listener.

For this purpose, the RTC SDK provides you with two global procedures in the "rtcConn" unit ...

procedure rtcSetupReceivingParams ( MRU:word=0; ReceivingBuffer:byte=0; MaxReadPackets:byte=0 );
  MRU = "Maximum Receive Unit" = Receiving Packet Size in Bytes (default = 1500 Bytes)
  ReceivingBuffer = Number of Packets that should fit into the Receiving Buffer (default = maximize input buffers)
  MaxReadPackets = Maximum number of Packets to be extracted from Receiving buffers with a single Read operation (default = entire input buffer)

procedure rtcSetupSendingParams ( MTU:word=0; SendingBuffer:byte=0; MaxWritePackets:byte=0 );
  MTU = "Maximum Transmit Unit" = Sending Packet Size in Bytes (default = 1500 Bytes)
  SendingBuffer = Number of Packets to fit into the Sending buffer (default = maximize output buffers)
  MaxWritePackets = Maximum number of Packets to be sent from Sending buffers with a single Write operation (default = entire output buffer)

The "tricky" part is to find optimal values for your specific Network, Server and Application configuration.

Using larger buffers can increase throughput when the Network is under low-to-medium load (up to a certain point, after which increasing buffers won't have any positive effect on throughput), but ... if you have more buffers than your Application can handle in a "timely manner", you are likely to cause Network Congestion when your Server load increases. Very high CPU-, Disk- or Memory-Usage is usually an indication of that problem, especially if Network traffic appears to be low.

On the other hand, using smaller buffers can reduce the chance of Network Congestion, but ... using too small buffers also reduces throughput and usually results in higher CPU usage, because less data will be sent and/or received with a single API call, so more API calls will be required to receive and/or send the same amount of data. And ... if you are processing data as it arrives (for example: writing data to disk or database to reduce memory usage), more events are likely to get triggered for the same amount of data received.

The following two lines of code, executed before you start the Server listener, are most likely going to avoid Network Congestion, so you can start with these and see if it stabilizes your Network usage when the Server is under high load:

  rtcSetupReceivingParams(1500,3,3); // 1500 MRU, 3 packets receiving buffers, read max 3 packet at once
  rtcSetupSendingParams(1500,12,12); // 1500 MTU, 12 packets sending buffers, write max 12 packets at once

If that helps with Network Congestion (your Network usage is stable, even under high load), you can try using higher values for sending and/or receiving parameters, until you find a "sweet spot". If your values are too high, you will either see that there is NO POSITIVE EFFECT on throughput, or start experiencing NEGATIVE SIDE-EFFECTS of using too high buffers when the Network Congestion starts "kicking-in" again.

It is also possible that the values I've listed above do NOT help avoid Network Congestion. If that is the case, then your Server configuration is probably too low (your available CPU, Disk speed or Network bandwidth is too low for optimal Application Server performance), so you will probably have to use even smaller buffers to keep your Network usage stable, reducing Network throughput to reduce the load to your Server until you find the values that work for you.

For example, below are values that produced optimal results while I was testing a RTC Gateway running on a VPS with a 4*2.4 GHz CPU using 2 GB RAM on a 1 GBit Network, using a few thousand Clients to stream large amounts of data to each other, but ... please keep in mind that a different Network or different configuration (or even using the Application differently) will usually require a different set of parameters to produce the best results, so do NOT simply copy/paste these two lines of code and expect all your problems to be solved ...

  rtcSetupReceivingParams(1500,2,2); // 1500 MRU, use 2 packets for receiving buffers, reading 2 packets at a time
  rtcSetupSendingParams(1500,0,0); // 1500 MTU, maximize sending buffers (using default values)

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 17 queries.