Hi everyone,
I’m having a question about the Delay node in Node-RED when using the rate limit option. (Node red version 4.0.8)
For example, I configured the node to 10 messages per minute, but the behavior is not what I expected.
Instead of allowing up to 10 messages anywhere within the minute, the node seems to allow one message every 6 seconds, as if it were converting the rate limit into a fixed interval. I don't know exactly if it does maths in seconds, miliseconds, ...
In other words:
- What I expected: a maximum of 10 messages in any 60-second window
- What I get: (see and test example below)
The result is not what I expect, since I need to allow short bursts as long as the total per day is not exceeded.
Is this the expected behavior of the Delay node?
Is there a native way (or a recommended alternative) in Node-RED to implement a true sliding-window rate limit, instead of this strange behaviour?
Thanks in advance for any help.
Example:
- The attached flow is a minimal example to show the behavior I’m seeing.
- Use two inject nodes.
- If you send 5 msg at 1 msg each 7 seconds, all messages are correctly sent to 1st output in delay node
- If you send 5 msg at 1 msg each 5 seconds, same of them are sent to 2nd output despite the rate is less than 10 msg/minute.
- the 10msg/min node has an strange behaviour, hasn't it?
[
{
"id": "5704b41a79567472",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "60c6aa58e443d024",
"type": "debug",
"z": "5704b41a79567472",
"name": "debug",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1170,
"y": 260,
"wires": []
},
{
"id": "fc774e569bf24db2",
"type": "change",
"z": "5704b41a79567472",
"name": "",
"rules": [
{
"t": "set",
"p": "out",
"pt": "msg",
"to": "2nd",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1030,
"y": 320,
"wires": [
[
"60c6aa58e443d024"
]
]
},
{
"id": "c67a43335950adbe",
"type": "delay",
"z": "5704b41a79567472",
"name": "10/min",
"pauseType": "rate",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "10",
"nbRateUnits": "1",
"rateUnits": "minute",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": true,
"allowrate": false,
"outputs": 2,
"x": 810,
"y": 320,
"wires": [
[
"60c6aa58e443d024"
],
[
"fc774e569bf24db2"
]
]
},
{
"id": "f9d520e7e8f322f3",
"type": "inject",
"z": "5704b41a79567472",
"name": "",
"props": [
{
"p": "timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 270,
"y": 320,
"wires": [
[
"455b795e61c69190"
]
]
},
{
"id": "8eca9fe9dfbcd446",
"type": "delay",
"z": "5704b41a79567472",
"name": "",
"pauseType": "rate",
"timeout": "7",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "7",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 640,
"y": 320,
"wires": [
[
"c67a43335950adbe"
]
]
},
{
"id": "455b795e61c69190",
"type": "function",
"z": "5704b41a79567472",
"name": "send 5 msg",
"func": "const messages = [];\nfor(let i = 0; i < 5; i++){\n messages.push({\n nr: i+1\n });\n}\nreturn [messages];",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 430,
"y": 320,
"wires": [
[
"8eca9fe9dfbcd446"
]
]
},
{
"id": "99f7af637ff2c8f1",
"type": "inject",
"z": "5704b41a79567472",
"name": "",
"props": [
{
"p": "timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 270,
"y": 400,
"wires": [
[
"7ca23bbaf6e198c4"
]
]
},
{
"id": "2db82a9f2d0c4fbd",
"type": "delay",
"z": "5704b41a79567472",
"name": "",
"pauseType": "rate",
"timeout": "7",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "5",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 640,
"y": 400,
"wires": [
[
"c67a43335950adbe"
]
]
},
{
"id": "7ca23bbaf6e198c4",
"type": "function",
"z": "5704b41a79567472",
"name": "send 5 msg",
"func": "const messages = [];\nfor(let i = 0; i < 5; i++){\n messages.push({\n nr: i+1\n });\n}\nreturn [messages];",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 430,
"y": 400,
"wires": [
[
"2db82a9f2d0c4fbd"
]
]
}
]
