All Projects → David-Desmaisons → Ratelimiter

David-Desmaisons / Ratelimiter

Licence: mit
C# rate limiting utility

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Ratelimiter

Simplenet
An easy-to-use, event-driven, asynchronous network application framework compiled with Java 11.
Stars: ✭ 164 (+3.14%)
Mutual labels:  asynchronous, client
EnumerableAsyncProcessor
Process Multiple Asynchronous Tasks in Various Ways - One at a time / Batched / Rate limited / Concurrently
Stars: ✭ 84 (-47.17%)
Mutual labels:  asynchronous, rate-limiting
Async Mqtt Client
📶 An Arduino for ESP8266 asynchronous MQTT client implementation
Stars: ✭ 555 (+249.06%)
Mutual labels:  asynchronous, client
Aspnetcoreratelimit
ASP.NET Core rate limiting middleware
Stars: ✭ 2,199 (+1283.02%)
Mutual labels:  rate-limiting
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-9.43%)
Mutual labels:  asynchronous
Ambassador
Super lightweight web framework in Swift based on SWSGI
Stars: ✭ 152 (-4.4%)
Mutual labels:  asynchronous
Potatso
Potatso is an iOS client that implements Shadowsocks proxy with the leverage of NetworkExtension framework. ***This project is unmaintained, try taking a look at this fork https://github.com/shadowcoel/shadowcoel instead.
Stars: ✭ 1,925 (+1110.69%)
Mutual labels:  client
Qtpromise
Promises/A+ implementation for Qt/C++
Stars: ✭ 137 (-13.84%)
Mutual labels:  asynchronous
Tryton
Mirror of Tryton Client
Stars: ✭ 156 (-1.89%)
Mutual labels:  client
Rolisteam
Rolisteam is a virtual tabletop. It helps you to manage tabletop role playing games with remote friends/players. It provides many features to share maps, pictures, dice roller, manage background music and much more. The main git repository is available here: [https://invent.kde.org/kde/rolisteam].
Stars: ✭ 151 (-5.03%)
Mutual labels:  client
Dhcpcd
DHCP / IPv4LL / IPv6RA / DHCPv6 client.
Stars: ✭ 148 (-6.92%)
Mutual labels:  client
Ether.network
https://github.com/Eastrall/Sylver
Stars: ✭ 147 (-7.55%)
Mutual labels:  client
Play Redis
Play framework 2 cache plugin as an adapter to redis-server
Stars: ✭ 152 (-4.4%)
Mutual labels:  asynchronous
Tokio
A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
Stars: ✭ 14,278 (+8879.87%)
Mutual labels:  asynchronous
Gophertunnel
Toolbox for Minecraft software written in Go
Stars: ✭ 156 (-1.89%)
Mutual labels:  client
Http Client
Http client that handles retries, logging & dynamic headers.
Stars: ✭ 144 (-9.43%)
Mutual labels:  client
Applemusicultra
Music Client for macOS. Upgrade your music experience with themes, styles, custom scripting and more. Uses WebKit and JavaScript.
Stars: ✭ 155 (-2.52%)
Mutual labels:  client
Elasticsearch Ruby
Ruby integrations for Elasticsearch
Stars: ✭ 1,848 (+1062.26%)
Mutual labels:  client
Kubernetes asyncio
Python asynchronous client library for Kubernetes http://kubernetes.io/
Stars: ✭ 147 (-7.55%)
Mutual labels:  asynchronous
Deeply
PHP client for the DeepL.com translation API (unofficial)
Stars: ✭ 152 (-4.4%)
Mutual labels:  client

RateLimiter

build codecov NuGet Badge MIT License

C# client-side rate limiting utility.

http://david-desmaisons.github.io/RateLimiter/

Motivation

The initial motivation was to create helper to respect Web Services rate limit in client application. However this helper can also be also in other scenarios where you need to temporally limit the usage of one shared resource.

Features

  • Easy to use
  • Fully asynchronous: lower resource usage than thread sleep
  • Cancellable via CancellationToken
  • Thread safe so you can share time constraints object to rate limit different threads using the same resource
  • Composable: ability to compose different rate limits in one constraint

Installation

Install-Package RateLimiter -Version 2.2.0

Sample usage

Basic

RateLimiters are awaitable: the code executed after the await will respect the time constraint:

    using ComposableAsync;

    // Create Time constraint: max five times by second
    var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(5, TimeSpan.FromSeconds(1));

    // Use it
    for(int i=0; i<1000; i++)
    {
        await timeConstraint;
        Trace.WriteLine(string.Format("{0:MM/dd/yyy HH:mm:ss.fff}", DateTime.Now));
    }

Output

05/23/2016 00:14:44.791
05/23/2016 00:14:44.958
05/23/2016 00:14:44.959
05/23/2016 00:14:44.959
05/23/2016 00:14:44.960
05/23/2016 00:14:45.959
05/23/2016 00:14:45.960
05/23/2016 00:14:45.961
05/23/2016 00:14:45.961
05/23/2016 00:14:45.962
05/23/2016 00:14:46.973
...

As http DelegatingHandler

    using System.Net.Http;

    //...
    var handler = TimeLimiter
            .GetFromMaxCountByInterval(60, TimeSpan.FromMinutes(1))
            .AsDelegatingHandler();
    var Client = new HttpClient(handler)

With cancellation token:

    // Create Time constraint: max three times by second
    var timeConstraint = TimeLimiter.GetFromMaxCountByInterval(3, TimeSpan.FromSeconds(1));
    var cancellationSource = new CancellationTokenSource(1100);

    // Use it
    while(true)
    {
        await timeConstraint.Enqueue(ConsoleIt, cancellationSource.Token);
    }
    
    //....
    private static void ConsoleIt()
    {
        Trace.WriteLine(string.Format("{0:MM/dd/yyy HH:mm:ss.fff}", DateTime.Now));
    }

Output

07/07/2019 18:09:35.645
07/07/2019 18:09:35.648
07/07/2019 18:09:35.648
07/07/2019 18:09:36.649
07/07/2019 18:09:36.650
07/07/2019 18:09:36.650

Composed

    // Create first constraint: max five times by second
    var constraint = new CountByIntervalAwaitableConstraint(5, TimeSpan.FromSeconds(1));
    
    / /Create second constraint: one time each 100 ms
    var constraint2 = new CountByIntervalAwaitableConstraint(1, TimeSpan.FromMilliseconds(100));
    
    // Compose the two constraints
    var timeConstraint = TimeLimiter.Compose(constraint, constraint2);

    // Use it
    for(int i=0; i<1000; i++)
    {
        await timeConstraint;
        Trace.WriteLine(string.Format("{0:MM/dd/yyy HH:mm:ss.fff}", DateTime.Now));
    }       

Output

05/21/2016 23:52:48.573
05/21/2016 23:52:48.682
05/21/2016 23:52:48.809
05/21/2016 23:52:48.922
05/21/2016 23:52:49.024
05/21/2016 23:52:49.575
05/21/2016 23:52:49.685
05/21/2016 23:52:49.810
05/21/2016 23:52:49.942
...
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].