Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Throttle algorithm

i would like to implement a good throttle algorithm by in .net (C# or VB) but i cannot figure out how could i do that.

The case is my asp.net website should post requests to another website to fetch results. At maximum 300 requests per minute should be sent.

If the requests exceed the 300 limit the other party Api returns nothing (Which is something i would not like to use as a check in my code).

P.S. I have seen solutions in other languages than .net but i am a newbie and please be kind and keep your answers as simple as 123.

Thank you

like image 353
OrElse Avatar asked Jan 03 '12 07:01

OrElse


People also ask

Is throttling illegal?

Is Throttling Legal? Throttling an internet connection is like a sneaky business that shortchanges its customers. Nonetheless, throttling is a legal practice, as long as ISPs adequately explain it to their customers. On the other hand, failure to inform customers about throttling is illegal.

How do I bypass Internet throttling?

What's the best way to bypass bandwidth throttling? If your ISP is throttling your bandwidth, and switching providers is not an option, the easiest solution is to connect through VPN. Your ISP won't be able to inspect the data packets, so it won't be able to throttle that traffic based on what service you're using.

How can I tell if my Verizon is being throttled?

Check your internet speed to see if Verizon is throttling your service. You can use websites to identify your internet speed, such as Fast.com and Speedtest.net. If your internet speed is noticeably slower than usual, then it is possible that your data speed is being restricted.

How do I tell if my internet is being throttled?

Signs of Internet ThrottlingSpecific websites or services are slower than others. Videos are buffering or lagging. Your internet speeds are slower than usual. Your Wi-Fi connection is choppy or broken.


1 Answers

You could have a simple application (or session) class and check that for hits. This is something extremely rough just to give you the idea:

public class APIHits {
    public int hits { get; private set; }
    private DateTime minute = DateTime.Now();

    public bool AddHit()
    {
        if (hits < 300) {
            hits++;
            return true;
        }
        else
        {
            if (DateTime.Now() > minute.AddSeconds(60)) 
            {
                //60 seconds later
                minute = DateTime.Now();
                hits = 1;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
like image 159
Prescott Avatar answered Oct 04 '22 09:10

Prescott