JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 98
  • Score
    100M100P100Q86183F
  • License ISC

implements rate limit with sliding window

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cameo69/node-red-ratelimit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    @cameo69/node-red-ratelimit

    A simple node that offers rate limiting based on a sliding window.

    General rate limiting

    Rate limiting based on a sliding window means that for any specified time interval no more than the specified number of messages will pass the rate-limiter node. Rate-limiter node will not delay any messages if the rate limit is not reached.

    That means even bursts of messages are allowed to pass within the given limit, while the passage of constant high message rates can be avoided. This is unlike the default delay-node (in rate limit mode), which will put a fixed time between each message even before the set rate limit is reached.

    Messages per time period

    The User can specify a maximum number of messages (n) for a time period (t).

    image

    For every incoming message the node checks if the number of messages sent in the last time frame t is below n; if yes, the message will be sent to output 1; if no, the message will be dropped, sent to output 2, or queued. Depending on the settings. If messages are queued, they will be release on output 1 whenever they will not exceed the set rate limit.

    Application

    A classic application could be the input protection of a flow that receives messages from the outside world, e.g. web requests or commands via MQTT. If the message rate is normal, messages are forwarded without any delay; but if there is too high volume, the messages are limited.

    Settings of @cameo69/node-red-ratelimit

    Modes of rate limiting

    Rate-limiter node can operate in 2 rate-limiting modes:

    • Queue intermediate messages
    • Drop intermediate messages

    Modes can be selected via dropdown menu in the node's editor.

    Drop intermediate messages

    In drop mode, rate-limiter will drop all messages above the limit. They will never reach the output 1.

    image

    There is a checkbox that allows sending those dropped messages to output 2.

    Example 1, drop intermediate

    Let's assume this setting:

    image

    The animation shows messages that are allowed to pass (green) and dropped messages (red) when the rate limit is reached.

    output_rate-limiter03

    Queue intermediate messages

    In queueing mode, rate-limiter allows to buffer messages that could not be sent immediately because they would have violated the rate limit. The messages will be sent as soon as they will not violate the rate limit.

    image

    Additionally, the user can set a maximum queue size. If the number of queued messages reaches the limit further messages can (depending on the setting) either be dropped or added to the queue while the oldest messages in the queue will be dropped.

    Drop oldest message if queue is full

    image

    Drop new messages if queue is full

    image

    Example 2, queueing unlimited

    For example let's assume this setting:

    image
    • The rate is set to 5 msg(s) per 10 seconds. --> Means if there is equal or less than 5 messages received in 10 seconds, they are sent to output 1.
    • Queue intermediate messages --> All messages above the limit of 5 messages will be buffered for later sending and...
    • Queue Max Size equals 0 which means with no limit --> No message will be dropped.

    If the node receives for example 6 messages within 10 secoonds, only 5 are sent immediately, and the 6th message will be sent exactly 10 secoonds after the first message, because then there were only 4 messages sent in the past 10 seconds, hence the 6th can be sent before the limit is reached again.

    Node

    image

    Settings dialog

    image

    Example

    output_rate-limiter01

    Nodered.org https://flows.nodered.org/node/@cameo69/node-red-ratelimit

    npm https://www.npmjs.com/package/@cameo69/node-red-ratelimit

    GitHub https://github.com/cameo69/node-red-contrib-ratelimit