express-rate-limit vs limiter vs bottleneck vs ratelimiter vs p-limit vs rate-limiter-flexible
ウェブ開発におけるレートリミッターライブラリ
express-rate-limitlimiterbottleneckratelimiterp-limitrate-limiter-flexible類似パッケージ:

ウェブ開発におけるレートリミッターライブラリ

レートリミッターライブラリは、アプリケーションが特定の時間内に行うリクエストの数を制限するために使用されます。これにより、サーバーの過負荷を防ぎ、APIの使用を管理し、悪意のある攻撃から保護することができます。これらのライブラリは、特に高トラフィックの環境や、リソースを効率的に管理する必要がある場合に重要です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
express-rate-limit25,144,9563,233141 kB83日前MIT
limiter11,113,0451,558158 kB141年前MIT
bottleneck10,649,7181,976-897年前MIT
ratelimiter178,588725-116年前MIT
p-limit02,81514.9 kB01ヶ月前MIT
rate-limiter-flexible03,485198 kB151ヶ月前ISC

機能比較: express-rate-limit vs limiter vs bottleneck vs ratelimiter vs p-limit vs rate-limiter-flexible

機能性

  • express-rate-limit:

    express-rate-limitは、HTTPリクエストに対して簡単にレート制限を設定できる機能を提供します。特定のルートやメソッドに対して異なる制限を設定でき、ミドルウェアとして簡単に統合可能です。

  • limiter:

    Limiterは、基本的なレート制限機能を提供します。シンプルなAPIで、特定の時間内に許可されるリクエスト数を設定できます。

  • bottleneck:

    Bottleneckは、タスクの実行を制御するための多くの機能を提供します。特定の時間内に実行できるタスクの数を制限し、バースト処理をサポートします。

  • ratelimiter:

    ratelimiterは、シンプルなレート制限機能を提供し、特に小規模なアプリケーションに適しています。使いやすく、すぐに実装できます。

  • p-limit:

    p-limitは、Promiseを返す関数の同時実行数を制限する機能を提供します。これにより、非同期処理の効率を向上させることができます。

  • rate-limiter-flexible:

    rate-limiter-flexibleは、複雑なレート制限を設定できる柔軟性を持っています。IPアドレスやユーザーIDに基づいて制限を設定でき、Redisなどの外部ストレージを使用することも可能です。

設定の柔軟性

  • express-rate-limit:

    express-rate-limitは、各ルートに対して異なる制限を設定できるため、柔軟性がありますが、全体的にはシンプルな設定です。

  • limiter:

    Limiterは、基本的な設定が可能ですが、他のライブラリと比べると柔軟性は低いです。

  • bottleneck:

    Bottleneckは、タスクの実行間隔や最大同時実行数を細かく設定できるため、非常に柔軟です。

  • ratelimiter:

    ratelimiterは、シンプルな設定で使いやすいですが、柔軟性は他のライブラリに比べて低いです。

  • p-limit:

    p-limitは、Promiseの同時実行数を制限するためのシンプルな設定が可能で、柔軟性があります。

  • rate-limiter-flexible:

    rate-limiter-flexibleは、非常に柔軟な設定が可能で、さまざまな条件に基づいて制限を設定できます。

パフォーマンス

  • express-rate-limit:

    express-rate-limitは、ミドルウェアとして非常に軽量で、パフォーマンスに優れています。

  • limiter:

    Limiterは、シンプルな実装のため、パフォーマンスが良好です。

  • bottleneck:

    Bottleneckは、タスクの実行を効率的に管理し、過負荷を防ぐための最適化がされています。

  • ratelimiter:

    ratelimiterは、シンプルな実装のため、パフォーマンスが良好ですが、大規模なシステムには向いていないかもしれません。

  • p-limit:

    p-limitは、Promiseの処理を効率的に管理するため、パフォーマンスが高いです。

  • rate-limiter-flexible:

    rate-limiter-flexibleは、Redisなどを使用することで、スケーラブルなパフォーマンスを提供します。

使用シナリオ

  • express-rate-limit:

    express-rate-limitは、ExpressアプリケーションでのHTTPリクエスト制限に最適です。

  • limiter:

    Limiterは、基本的なレート制限が必要な場合に適しています。

  • bottleneck:

    Bottleneckは、APIリクエストの制御や、複数の非同期タスクを管理する際に特に有用です。

  • ratelimiter:

    ratelimiterは、小規模なアプリケーションやシンプルな実装が必要な場合に適しています。

  • p-limit:

    p-limitは、Promiseベースのタスクを効率的に管理したい場合に最適です。

  • rate-limiter-flexible:

    rate-limiter-flexibleは、複雑なレート制限が必要な場合や、分散システムでの使用に適しています。

学習曲線

  • express-rate-limit:

    express-rate-limitは、シンプルなAPIのため、学習が容易です。

  • limiter:

    Limiterは、非常にシンプルで、すぐに使い始めることができます。

  • bottleneck:

    Bottleneckは、多機能であるため、学習曲線がやや急ですが、使いこなすことで強力な制御が可能です。

  • ratelimiter:

    ratelimiterは、シンプルな実装のため、学習が非常に簡単です。

  • p-limit:

    p-limitは、Promiseに特化しているため、Promiseの理解があれば簡単に学習できます。

  • rate-limiter-flexible:

    rate-limiter-flexibleは、柔軟性が高いため、学習には少し時間がかかるかもしれませんが、強力な機能を提供します。

選び方: express-rate-limit vs limiter vs bottleneck vs ratelimiter vs p-limit vs rate-limiter-flexible

  • express-rate-limit:

    Expressアプリケーションで簡単に使用できるシンプルなレートリミッターを探している場合は、express-rate-limitが適しています。ミドルウェアとして簡単に統合でき、特定のルートに対して制限を設定できます。

  • limiter:

    Limiterは、シンプルで軽量なレートリミッターを提供します。特に、基本的なリクエスト制限が必要な場合に適しており、設定が簡単です。

  • bottleneck:

    Bottleneckは、複雑なリクエスト制御が必要な場合に最適です。特に、複数のタスクを同時に実行し、各タスクの実行速度を調整したい場合に有用です。

  • ratelimiter:

    ratelimiterは、シンプルで使いやすいレートリミッターで、特に小規模なプロジェクトや簡単な実装が必要な場合に適しています。

  • p-limit:

    p-limitは、Promiseベースのタスクを制限するためのライブラリです。非同期処理を効率的に管理したい場合に最適です。

  • rate-limiter-flexible:

    柔軟な設定が可能なレートリミッターを必要とする場合は、rate-limiter-flexibleが適しています。Redisなどのストレージを使用して、分散環境での利用にも対応しています。

express-rate-limit のREADME

express-rate-limit

tests npm version npm downloads license

Basic rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset. Plays nice with express-slow-down and ratelimit-header-parser.

Usage

The full documentation is available on-line.

import { rateLimit } from 'express-rate-limit'

const limiter = rateLimit({
	windowMs: 15 * 60 * 1000, // 15 minutes
	limit: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
	standardHeaders: 'draft-8', // draft-6: `RateLimit-*` headers; draft-7 & draft-8: combined `RateLimit` header
	legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
	ipv6Subnet: 56, // Set to 60 or 64 to be less aggressive, or 52 or 48 to be more aggressive
	// store: ... , // Redis, Memcached, etc. See below.
})

// Apply the rate limiting middleware to all requests.
app.use(limiter)

Data Stores

The rate limiter comes with a built-in memory store, and supports a variety of external data stores.

Configuration

All function options may be async. Click the name for additional info and default values.

OptionTypeRemarks
windowMsnumberHow long to remember requests for, in milliseconds.
limitnumber | functionHow many requests to allow.
messagestring | json | functionResponse to return after limit is reached.
statusCodenumberHTTP status code after limit is reached (default is 429).
handlerfunctionFunction to run after limit is reached (overrides message and statusCode settings, if set).
legacyHeadersbooleanEnable the X-Rate-Limit header.
standardHeaders'draft-6' | 'draft-7' | 'draft-8'Enable the Ratelimit header.
identifierstring | functionName associated with the quota policy enforced by this rate limiter.
storeStoreUse a custom store to share hit counts across multiple nodes.
passOnStoreErrorbooleanAllow (true) or block (false, default) traffic if the store becomes unavailable.
keyGeneratorfunctionIdentify users (defaults to IP address).
ipv6Subnetnumber (32-64) | function | falseHow many bits of IPv6 addresses to use in default keyGenerator
requestPropertyNamestringAdd rate limit info to the req object.
skipfunctionReturn true to bypass the limiter for the given request.
skipSuccessfulRequestsbooleanUncount 1xx/2xx/3xx responses.
skipFailedRequestsbooleanUncount 4xx/5xx responses.
requestWasSuccessfulfunctionUsed by skipSuccessfulRequests and skipFailedRequests.
validateboolean | objectEnable or disable built-in validation checks.

Thank You

Sponsored by Zuplo a fully-managed API Gateway for developers. Add dynamic rate-limiting, authentication and more to any API in minutes. Learn more at zuplo.com

zuplo-logo


Thanks to Mintlify for hosting the documentation at express-rate-limit.mintlify.app

Create your docs today


Finally, thank you to everyone who's contributed to this project in any way! 🫶

Issues and Contributing

If you encounter a bug or want to see something added/changed, please go ahead and open an issue! If you need help with something, feel free to start a discussion!

If you wish to contribute to the library, thanks! First, please read the contributing guide. Then you can pick up any issue and fix/implement it!

License

MIT © Nathan Friedly, Vedant K