All Projects → bosima → FireflySoft.RateLimit

bosima / FireflySoft.RateLimit

Licence: Apache-2.0 license
It is a rate limiting library based on .Net standard.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to FireflySoft.RateLimit

gentle-force
Brute-force, error and request rate limiting
Stars: ✭ 45 (-40.79%)
Mutual labels:  rate-limiting, leaky-bucket, rate-limit, token-bucket
leaky-bucket
A tokio-based leaky bucket rate limiter
Stars: ✭ 32 (-57.89%)
Mutual labels:  leaky-bucket, token-bucket
RateLimiter
简单限流算法实现
Stars: ✭ 22 (-71.05%)
Mutual labels:  leaky-bucket, token-bucket
adaptive throttler
manages multiple throttlers with ability to ramp up and down
Stars: ✭ 31 (-59.21%)
Mutual labels:  rate-limiting, rate-limit
freebind
IPv4 and IPv6 address rate limiting evasion tool
Stars: ✭ 88 (+15.79%)
Mutual labels:  rate-limiting, rate-limit
aiolimiter
An efficient implementation of a rate limiter for asyncio.
Stars: ✭ 121 (+59.21%)
Mutual labels:  rate-limiting, leaky-bucket
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (-68.42%)
Mutual labels:  aspnetcore, dotnet-framework
flaps
🛬 Modular rate limiting for PHP.
Stars: ✭ 64 (-15.79%)
Mutual labels:  rate-limiting, leaky-bucket
MiCake
🍰一款基于.Net Core平台的“超轻柔“领域驱动设计(DDD)组件
Stars: ✭ 112 (+47.37%)
Mutual labels:  aspnetcore
Reloaded.Assembler
Minimal .NET wrapper around the simple, easy to use Flat Assembler written by Tomasz Grysztar. Supports both x64 and x86 development.
Stars: ✭ 17 (-77.63%)
Mutual labels:  memory
go-ratelimit
Ratelimit your methods using Redis
Stars: ✭ 37 (-51.32%)
Mutual labels:  rate-limiting
ApiFramework
Everything is an (Open)API
Stars: ✭ 26 (-65.79%)
Mutual labels:  aspnetcore
Ext.NET
Ext.NET public Issues.
Stars: ✭ 28 (-63.16%)
Mutual labels:  aspnetcore
Abp.AspNetCoreRateLimit
An Abp module helps you control how often your service is used.
Stars: ✭ 19 (-75%)
Mutual labels:  rate-limiting
NoSpawnChunks
Helps manage server memory by dynamically unloading chunks
Stars: ✭ 21 (-72.37%)
Mutual labels:  memory
KissLog.Sdk
KissLog is a lightweight and highly customizable logging framework for .NET applications
Stars: ✭ 33 (-56.58%)
Mutual labels:  aspnetcore
Osuplay
リズムゲーム「osu!」の譜面に使用されている楽曲を一覧表示して、再生できるソフトウェアです。
Stars: ✭ 19 (-75%)
Mutual labels:  dotnet-framework
audria
audria - A Utility for Detailed Ressource Inspection of Applications
Stars: ✭ 35 (-53.95%)
Mutual labels:  memory
dotNetify-react-native-demo
DotNetify + React Native + .NET Core demo
Stars: ✭ 43 (-43.42%)
Mutual labels:  aspnetcore
Abp.Castle.NLog
Abp的NLog日志输出模块。
Stars: ✭ 15 (-80.26%)
Mutual labels:  aspnetcore

FireflySoft.RateLimit           中文

Introduction

Fireflysoft.RateLimit is a rate limiting library based on .Net standard. Its core is simple and lightweight, and can flexibly meet the rate limiting needs of many scenarios.

Features

  • Multiple rate limiting algorithms: built-in fixed window, sliding window, leaky bucket, token bucket, and can be extended.
  • Multiple counting storage: memory and Redis (including cluster).
  • Distributed friendly: supports unified counting of distributed programs with Redis storage.
  • Flexible rate limiting targets: each data can be extracted from the request to set rate limiting targets.
  • Support rate limit penalty: the client can be locked for a period of time after the rate limit is triggered.
  • Time window enhancement: support to the millisecond level; support starting from the starting point of time periods such as seconds, minutes, hours, dates, etc.
  • Real-time tracking: the number of requests processed and the remaining allowed requests in the current counting cycle, as well as the reset time of the counting cycle.
  • Dynamically change the rules: support the dynamic change of the rate limiting rules when the program is running.
  • Custom error: you can customize the error code and error message after the current limit is triggered.
  • Universality: in principle, it can meet any scenario that requires rate limiting.

Projects

Project Descriptioin
FireflySoft.RateLmit.Core algorithm, rules, persistence and other core codes.
FireflySoft.RateLimit.AspNet ASP.NET rate-limit middleware based on .NET Framework.
FireflySoft.RateLimit.AspNetCore ASP.NET Core rate-limit middleware.
FireflySoft.RateLimit.Core.UnitTest Unit test for FireflySoft.RateLimit.Core.
FireflySoft.RateLimit.Core.BenchmarkTest Benchmark test for FireflySoft.RateLimit.Core.
Samples/Console FireflySoft.RateLmit.Core sample program.
Samples/AspNet FireflySoft.RateLimit.AspNet sample program.
Samples/AspNetCore FireflySoft.RateLimit.AspNetCore sample program.
Samples/RuleAutoUpdate A sample that can automatic update rate limiting rules.

Usage

ASP.NET Core

1、Install Nuget Package

Package Manager:

Install-Package FireflySoft.RateLimit.AspNetCore

Or .NET CLI:

dotnet add package FireflySoft.RateLimit.AspNetCore

Or Project file:

<ItemGroup>
<PackageReference Include="FireflySoft.RateLimit.AspNetCore" Version="2.*" />
</ItemGroup>

2、Use Middleware

The following code calls the rate-limit middleware from Startup.Configure:

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddRateLimit(new InProcessFixedWindowAlgorithm(
        new[] {
            new FixedWindowRule()
            {
                ExtractTarget = context =>
                {
                    return (context as HttpContext).Request.Path.Value;
                },
                CheckRuleMatching = context =>
                {
                    return true;
                },
                Name="default limit rule",
                LimitNumber=30,
                StatWindow=TimeSpan.FromSeconds(1)
            }
        })
    );

    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...

    app.UseRateLimit();

    ...
}

ASP.NET

1、Install Nuget Package:

Package Manager:

Install-Package FireflySoft.RateLimit.AspNet

2、Register MessageHandler

Open Global.asax.cs, the following code adds the rate limit message handle:

protected void Application_Start()
{
    ...

    GlobalConfiguration.Configuration.MessageHandlers.Add(
        new RateLimitHandler(
            new Core.InProcessAlgorithm.InProcessFixedWindowAlgorithm(
                new[] {
                    new FixedWindowRule()
                    {
                        ExtractTarget = context =>
                        {
                            return (context as HttpRequestMessage).RequestUri.AbsolutePath;
                        },
                        CheckRuleMatching = context =>
                        {
                            return true;
                        },
                        Name="default limit rule",
                        LimitNumber=30,
                        StatWindow=TimeSpan.FromSeconds(1)
                    }
                })
        ));

    ...
}

Others

1、Install Nuget Package

Package Manager:

Install-Package FireflySoft.RateLimit.Core

Or .NET CLI:

dotnet add package FireflySoft.RateLimit.Core

2、Use IAlgorithm

Use IAlgorithm to filter every request, process the return value of Check method.

// Rule
var fixedWindowRules = new FixedWindowRule[]
    {
        new FixedWindowRule()
        {
            Id = "3",
            StatWindow=TimeSpan.FromSeconds(1),
            LimitNumber=30,
            ExtractTarget = (request) =>
            {
                return (request as SimulationRequest).RequestResource;
            },
            CheckRuleMatching = (request) =>
            {
                return true;
            },
        }
    };

// Algorithm
IAlgorithm algorithm = new InProcessFixedWindowAlgorithm(fixedWindowRules);

// Check
var result = algorithm.Check(new SimulationRequest()
    {
        RequestId = Guid.NewGuid().ToString(),
        RequestResource = "home",
        Parameters = new Dictionary<string, string>() {
                    { "from","sample" },
            }
    });

SimulationRequest is a custom request that you can modify to any type.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].