{"id":19331976,"url":"https://github.com/tikv/async-speed-limit","last_synced_at":"2025-04-06T11:08:33.405Z","repository":{"id":36935237,"uuid":"230993380","full_name":"tikv/async-speed-limit","owner":"tikv","description":"Asynchronously speed-limiting multiple byte streams","archived":false,"fork":false,"pushed_at":"2023-08-07T08:02:17.000Z","size":44,"stargazers_count":53,"open_issues_count":1,"forks_count":15,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-25T00:55:38.609Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tikv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-Apache","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-30T23:24:47.000Z","updated_at":"2024-01-26T04:04:30.000Z","dependencies_parsed_at":"2024-11-10T02:43:24.221Z","dependency_job_id":"90f9d556-2cec-4eeb-b3f1-0fcdfae2ea69","html_url":"https://github.com/tikv/async-speed-limit","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fasync-speed-limit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fasync-speed-limit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fasync-speed-limit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fasync-speed-limit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tikv","download_url":"https://codeload.github.com/tikv/async-speed-limit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471519,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T02:43:20.719Z","updated_at":"2025-04-06T11:08:33.384Z","avatar_url":"https://github.com/tikv.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"async-speed-limit\n=================\n\n[![Build status](https://github.com/tikv/async-speed-limit/workflows/Rust/badge.svg)](https://github.com/tikv/async-speed-limit/actions?query=workflow%3ARust)\n[![Latest Version](https://img.shields.io/crates/v/async-speed-limit.svg)](https://crates.io/crates/async-speed-limit)\n[![Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/async-speed-limit)\n\nAsynchronously speed-limiting multiple byte streams (`AsyncRead` and `AsyncWrite`).\n\n## Usage\n\n```rust\nuse async_speed_limit::Limiter;\nuse futures_util::{\n    future::try_join,\n    io::{self, AsyncRead, AsyncWrite},\n};\nuse std::{marker::Unpin, pin::Pin};\n\n#[cfg(feature = \"standard-clock\")]\nasync fn copy_both_slowly(\n    r1: impl AsyncRead,\n    w1: \u0026mut (impl AsyncWrite + Unpin),\n    r2: impl AsyncRead,\n    w2: \u0026mut (impl AsyncWrite + Unpin),\n) -\u003e io::Result\u003c()\u003e {\n    // create a speed limiter of 1.0 KiB/s.\n    let limiter = \u003cLimiter\u003e::new(1024.0);\n\n    // limit both readers by the same queue\n    // (so 1.0 KiB/s is the combined maximum speed)\n    let r1 = limiter.clone().limit(r1);\n    let r2 = limiter.limit(r2);\n\n    // do the copy.\n    try_join(io::copy(r1, w1), io::copy(r2, w2)).await?;\n    Ok(())\n}\n```\n\n## Algorithm\n\nasync-speed-limit imposes the maximum speed limit using the [token bucket]\nalgorithm with a single queue. Transmission is throttled by adding a delay\nproportional to the consumed tokens *after* it is sent. Because of this, the\ntraffic flow will have high burstiness around when the token bucket is full.\n\nThe time needed to refill the bucket from empty to full is called the\n*refill period*. Reducing the refill period also reduces burstiness, but there\nwould be more sleeps. The default value (0.1 s) should be good enough for most\nsituations.\n\n[token bucket]: https://en.wikipedia.org/wiki/Token_bucket\n\n## Tokio 0.1\n\nasync-speed-limit is designed for \"Futures 0.3\". This package does not directly\nsupport Tokio 0.1, but you can use futures-util's [`compat` module] to bridge\nthe types.\n\n[futures-timer]: https://crates.io/crates/futures-timer\n[`compat` module]: https://docs.rs/futures-util/0.3/futures_util/compat/index.html\n\n## Cargo features\n\n| Name                         | Dependency      | Effect                                                                                    |\n|------------------------------|-----------------|-------------------------------------------------------------------------------------------|\n| **standard-clock** (default) | [futures-timer] | Enables the `clock::StandardClock` struct.                                                |\n| **fused-future** (default)   | [futures-core]  | Implements `FusedFuture` on `limiter::Consume`.                                           |\n| **futures-io** (default)     | [futures-io]    | Implements `AsyncRead` and `AsyncWrite` on `limiter::Resource`.                           |\n| ~~**read-initializer**~~     | -               | Deprecated and does nothing. This feature has been removed since `futures-io 0.3.19`.     |\n\n[futures-core]: https://crates.io/crates/futures-core\n[futures-io]: https://crates.io/crates/futures-io\n\n## License\n\nasync-speed-limit is dual-licensed under\n\n* Apache 2.0 license ([LICENSE-Apache](./LICENSE-Apache) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n* MIT license ([LICENSE-MIT](./LICENSE-MIT) or \u003chttps://opensource.org/licenses/MIT\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Fasync-speed-limit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftikv%2Fasync-speed-limit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Fasync-speed-limit/lists"}