Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bandwidth Shaping in my C# application

I have a C# application that uses a native library that sends video to other IP over the internet using UDP. I have no traffic control over that library.

My application also calls web services of another server using WebRequest that I have control over them.

The problem is:

When I have low internet bandwidth, the video stream uses all of my bandwidth. So I fail to get responses from my web service methods during that time.

Is there any way to prioritize the WebRequest or save some bandwidth for them so that I could get responses safely?

like image 592
Matin Lotfaliee Avatar asked Apr 25 '17 19:04

Matin Lotfaliee


People also ask

What is traffic shaping example?

The application-based traffic shaping technique prioritizes the data packets of some applications over others—for example, the voice data packets of a VoIP over the basic data packets of a browser.

What is shaping in WIFI?

Traffic shaping (also known as packet shaping) is bandwidth management technique that delays the flow of certain types of network packets in order to ensure network performance for higher priority applications.

Where is traffic shaping configured?

Traffic shaping can be configured at the system level or the interface level. System level queuing policies can be overridden by interface queuing policies. Traffic shaping might increase the latency of packets due to queuing, because it falls back to store-and-forward mode when packets get queued.


2 Answers

I do not know of any method in C# that can prioritize traffic in this way.

I know this is not quite a stack overflow kind of answer but this is how I have handled streaming services not killing the bandwidth in my environments when you have no proper networking infrastructure access which is the “proper” way of doing this.

When you conclude on what method you are going to use I recommend you take a look at https://superuser.com which should be able to answer any stumbling blocks you will have in implementing the solution.

Solution One.

Split into 2 services and communicate through REST API in each service or a database poll. Then use a network limiting program to prioritize the traffic of one of the services. https://www.netlimiter.com/ and https://netbalancer.com/ are examples of software that can do this but there are many more.

Advantage: You will have dynamic throttling of your streaming service.

Drawbacks: You will have to have another program running on the server and its definitely not free.

Solution Two.

Use IIS, There’s a built-in throttle in IIS https://www.iis.net/configreference/system.applicationhost/weblimits and look at maxGlobalBandWidth. Then you have 2 websites that communicate through REST or a database poll. Advantage: Simple out of the box solution.

Drawbacks: your limits are not dynamic and are in your config file.

Note that you should not use this method if your internet networking speed varies much.

like image 172
Archlight Avatar answered Oct 01 '22 18:10

Archlight


It is pretty straightforward to setup a UDP relay server for simple UDP streams, which you can then use to throttle the traffic as needed. You can put this in your application so everything is self-contained and your relay server is aware of when web requests are made. Create one UdpClient to receive traffic on 127.0.0.1 and have the video streaming library connect to that instead of your actual server. Then create another UdpClient that will relay the traffic to the actual destination that you normally connect to with the library.

You can limit bandwidth any number of ways with this method and how you do it will ultimately depend on your requirements. You can just pause forwarding of UDP frames whenever you start a web request and resume forwarding them after you get a response if pausing is acceptable. If not then you can track average UDP frames/second as you are relaying data and dynamically rate limit to 50% (or whatever) of that by inserting appropriate delays into your relay server while you have a web request pending.

You can look here for an example of a simple UDP relay server implementation for DNS requests, the basic principle would be the same:

https://social.msdn.microsoft.com/Forums/en-US/ce062e62-395f-4110-a4dd-3e9ed3c88286/udp-relay-server?forum=netfxnetcom

like image 36
Mike Marynowski Avatar answered Oct 01 '22 18:10

Mike Marynowski