GithubHelp home page GithubHelp logo
 photo

throttlingtroll Goto Github PK

repos: 1.0 gists: 0.0

Type: Organization

Bio: Rate limiting/throttling middleware for ASP.NET Core and Azure Functions

Location: Norway

ThrottlingTroll

Rate limiting/throttling middleware for ASP.NET Core and Azure Functions.

.NET Nuget

Nuget Nuget Nuget

Install from Nuget:

ASP.NET Core Azure Functions Azure Functions with ASP.NET Core Integration
dotnet add package ThrottlingTroll dotnet add package ThrottlingTroll.AzureFunctions dotnet add package ThrottlingTroll.AzureFunctionsAspNet

Features

Supported rate limiting algorithms

  • FixedWindow. No more than PermitLimit requests are allowed in IntervalInSeconds. Here is an illustration for the case of no more than 2 requests per each 8 seconds:

    The typical drawback of FixedWindow algorithm is that you'd get request rate bursts at the end of each window. So specifically to cope that we have

  • SlidingWindow. No more than PermitLimit requests are allowed in IntervalInSeconds, but that interval is split into NumOfBuckets. The main benefit of this algorithm over FixedWindow is that if a client constantly exceedes PermitLimit, it will never get any valid response and will always get 429 TooManyRequests. Here is an illustration for the case of no more than 2 requests per each 8 seconds with 2 buckets:

    In other words, with SlidingWindow your service gets a smoother request rate.

  • Semaphore aka Concurrency Limiter. No more than PermitLimit requests are allowed to be executed concurrently. Here is an illustration for the case of no more than 3 concurrent requests:

    If you set Semaphore's PermitLimit to 1 and use RedisCounterStore, then ThrottlingTroll will act as a distributed lock. If you add an IdentityIdExtractor (identifying requests by e.g. a query string parameter), then it will turn into named distributed locks.

You can find it in our Wiki.

Most concepts and features are the same for all supported platforms. Things that are specific to each platform are highlighted in the relevant READMEs:

ASP.NET Core Azure Functions Azure Functions with ASP.NET Core Integration
How to use with ASP.NET Core How to use with Azure Functions How to use with Azure Functions ASP.NET Core Integration

Samples

Full minimalistic sample using ASP.NET Core Minimal API:

using ThrottlingTroll;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello ThrottlingTroll!");

// Limiting to 1 request per 2 seconds
app.UseThrottlingTroll(options =>
{
    options.Config = new ThrottlingTrollConfig 
    {
        Rules =
        [
            new ThrottlingTrollRule
            {
                LimitMethod = new FixedWindowRateLimitMethod
                {
                    PermitLimit = 1,
                    IntervalInSeconds = 2
                }
            }
        ]
    };
});

app.Run();

Sample projects that demonstrate all the above concepts:

ASP.NET Core Azure Functions
ThrottlingTrollSampleWeb ThrottlingTrollSampleFunction
ThrottlingTrollSampleAspNetFunction
ThrottlingTrollSampleDotNet6InProcDurableFunction

Contributing

Is very much welcomed.

throttlingtroll's Projects

throttlingtroll icon throttlingtroll

Rate limiting/throttling middleware for ASP.NET Core and Azure Functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.