Crate extending futures stream combinators, that is adding precise rate limiter

Overview

stream-rate-limiter

Stream combinator

.rate_limiter(opt: RateLimitOptions)

Provides way to limit stream element rate with constant intervals. It adds some level of customization in case of stream delays inaccessible in "standard" solution (tokio-timer)

Before you use this library, please consider using tokio-timer crate (you can look at tokio_interval example)

If you need to limit stream rate with constant intervals, with additional customisation (increasing permanent stream delay in case of stream delays, which prevents flooding stream after huge hickups.

For example you want to produce a stream of elements with constant rate of 1 element per second. You can use this library to set rate limit to 1 element and for example 1 second of accepted delay. Thus after your stream is stuck for like couple of seconds your event won't be flooding but they go back to rate at one per second fast. You can also react and close the stream if delay is too big.

Case study

x axis is element number, y axis is time, element number 40 is simulated to stuck for 2 seconds)

When you want to delay stream after hiccup

stream::iter(0..101)
    .rate_limit(
        RateLimitOptions::empty()
        .with_min_interval_sec(0.02)
        .with_interval_sec(0.1)
        .with_allowed_slippage_sec(0.5)
        .on_stream_delayed(|sdi| StreamBehavior::Delay(sdi.current_delay)),
    )

alt text

When you want to allow stream to catchup after hiccup (continue option):

stream::iter(0..101)
    .rate_limit(
        RateLimitOptions::empty()
            .with_min_interval_sec(0.02)
            .with_interval_sec(0.1)
            .with_allowed_slippage_sec(0.5)
            .on_stream_delayed(|_sdi| StreamBehavior::Continue),
    )

alt text

When you want to stop stream after hiccup (stop option): Note that last element may appear depending on if the delay was before or after rate_limit. Hiccups may occur on any side of the stream. This extension (.rate_limit) does not differentiate where hiccups occure.

stream::iter(0..101)
.rate_limit(
    RateLimitOptions::empty()
        .with_min_interval_sec(0.02)
        .with_interval_sec(0.1)
        .with_allowed_slippage_sec(0.5)
        .on_stream_delayed(|_sdi| StreamBehavior::Stop),
    )

alt text

You might also like...
Stream & Download Cartoons & Animes

eren Stream & Download Cartoons & Animes Install Linux/Mac First of all install rust then git clone 'https://github.com/Based-Programmer/eren' && \ cd

Rust crate for configurable parallel web crawling, designed to crawl for content

url-crawler A configurable parallel web crawler, designed to crawl a website for content. Changelog Docs.rs Example extern crate url_crawler; use std:

Rust crate for scraping URLs from HTML pages

url-scraper Rust crate for scraping URLs from HTML pages. Example extern crate url_scraper; use url_scraper::UrlScraper; fn main() { let director

Library + CLI-Tool to measure the TTFB (time to first byte) of HTTP requests. Additionally, this crate measures the times of DNS lookup, TCP connect and TLS handshake.

TTFB: CLI + Lib to Measure the TTFB of HTTP/1.1 Requests Similar to the network tab in Google Chrome or Mozilla Firefox, this crate helps you find the

Safe Rust crate for creating socket servers and clients with ease.

bitsock Safe Rust crate for creating socket servers and clients with ease. Description This crate can be used for Client -- Server applications of e

Dav-server-rs - Rust WebDAV server library. A fork of the webdav-handler crate.

dav-server-rs A fork of the webdav-handler-rs project. Generic async HTTP/Webdav handler Webdav (RFC4918) is defined as HTTP (GET/HEAD/PUT/DELETE) plu

The netns-rs crate provides an ultra-simple interface for handling network namespaces in Rust.

netns-rs The netns-rs crate provides an ultra-simple interface for handling network namespaces in Rust. Changing namespaces requires elevated privileg

Rust utility crate for parsing, encoding and generating x25519 keys used by WireGuard

WireGuard Keys This is a utility crate for parsing, encoding and generating x25519 keys that are used by WireGuard. It exports custom types that can b

⏱ Cross-platform Prometheus style process metrics collector of metrics crate

⏱ metrics-process This crate provides Prometheus style process metrics collector of metrics crate for Linux, macOS, and Windows. Collector code is man

Releases(v0.3.1)
Owner
null
A crate for parsing HTTP rate limit headers as per the IETF draft

rate-limits A crate for parsing HTTP rate limit headers as per the IETF draft. Inofficial implementations like the Github rate limit headers are also

Matthias 3 Jul 9, 2022
Adding the macvlan functionality to Podman’s new network stack

Netavark DHCP Proxy Server See https://github.com/containers/netavark-dhcp-proxy for the newest changes Short Summary Adding the macvlan functionality

Jack 1 Sep 28, 2022
The gRPC library for Rust built on C Core library and futures

gRPC-rs gRPC-rs is a Rust wrapper of gRPC Core. gRPC is a high performance, open source universal RPC framework that puts mobile and HTTP/2 first. Sta

TiKV Project 1.6k Jan 7, 2023
Futures implementation for JSON-RPC

futures-jsonrpc Futures + JSON-RPC A lightweight remote procedure call protocol. It is designed to be simple! And, with futures, even more flexible! T

Victor Lopes 12 May 19, 2022
Futures-based QUIC implementation in Rust

Pure-rust QUIC protocol implementation Quinn is a pure-rust, future-based implementation of the QUIC transport protocol undergoing standardization by

null 2.6k Jan 8, 2023
Transforms UDP stream into (fake) TCP streams that can go through Layer 3 & Layer 4 (NAPT) firewalls/NATs.

Phantun A lightweight and fast UDP to TCP obfuscator. Table of Contents Phantun Latest release Overview Usage 1. Enable Kernel IP forwarding 2. Add re

Datong Sun 782 Dec 30, 2022
General-purpose asynchronous socket stream.

async-socket This crate implements a general-purpose asynchronous socket. The Socket implements AsyncRead, AsyncWrite, Stream and Clone traits and thu

Kristijan Sedlak 3 Oct 20, 2021
SpringQL: Open-source stream processor for IoT devices and in-vehicle computers

What is SpringQL? SpringQL is an open-source stream processor specialized in memory efficiency. It is supposed to run on embedded systems like IoT dev

SpringQL 25 Dec 26, 2022
Stream API for tokio-udp.

UDPflow Stream API for tokio-udp. TCP-like UDP stream use tokio::net::UdpSocket; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use udpflow::{UdpListen

zephyr 5 Dec 2, 2022
A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems.

x-server-stats A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems. x-server(in x-serv

Pratyaksh 11 Oct 17, 2022