npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rrnl-request-limiter-middleware

v1.3.0

Published

A RRNL middleware for limit number of request

Downloads

19

Readme

RRNL-request-limiter-middleware

A RRNL middleware for limit number of request

GitHub Repo stars last commit (branch)

latest version License npm downloads minimized gzipped size

Codecov workflow codecov

Why need this middleware?

Adding loose limits on the number of requests prevents applications from generating a large number of server requests in a short period of time, thus ultimately avoiding more serious problems

Despite the rigorous testing of our products, bugs that can't be reproduced are always there.

Despite our caching strategy. (with React-Relay cache policy or cache middleware)

Inexperienced developers can easily make the following mistakes

const res = useLazyLoadQuery(query, {
  startDateTime: moment().subtract(7, "day").format("l HH:mm:ss"), // last 7 day
});

Think about this: "If the request time is large then 1 second?"

The precision of the time parameter in variables is small, it is more likely to result in frequent requests.

How to use?

Install:

yarn add rrnl-request-limiter-middleware

// or npm install rrnl-request-limiter-middleware

Usage:

import {
  createRequestLimiterMiddleware,
  SlidingLogRateLimiter,
} from "rrnl-request-limiter-middleware";

const network = new RelayNetworkLayer([
  // your other middleware
  // ...
  cacheMiddleware(),
  createRequestLimiterMiddleware(
    new SlidingLogRateLimiter([
      { duration: 60_000, limitTimes: 60 }, // Maximum 60 requests in 60 second for a query id
      { duration: 1_000, limitTimes: 3 }, // Maximum 3 requests in 1 second for a query id
    ]),
  ),
  // your other middlewares
  // ...
]);

Use with TokenBucketRateLimiter:

import {
  createRequestLimiterMiddleware,
  TokenBucketRateLimiter,
} from "rrnl-request-limiter-middleware";

const network = new RelayNetworkLayer([
  // your other middleware
  // ...
  cacheMiddleware(),
  createRequestLimiterMiddleware(new TokenBucketRateLimiter(20, 1)),
  // your other middlewares
  // ...
]);

NOTE: Currently, TokenBucketRateLimiter does not distinguish between queryId limits, in order to avoid overly timed tasks.

With wait limit policy:

import {
  createRequestLimiterMiddleware,
  TokenBucketRateLimiter,
} from "rrnl-request-limiter-middleware";

const network = new RelayNetworkLayer([
  // your other middleware
  // ...
  cacheMiddleware(),
  createRequestLimiterMiddleware(new TokenBucketRateLimiter(20, 1), "wait"),
  // your other middlewares
  // ...
]);

How to contribute?

Contributing Guild

Changelog

Change Logs

License

MIT