Skip to content

Commit ff9e595

Browse files
committed
Merge branch 'pr_106' into flowdev
2 parents 208431b + e7c33e5 commit ff9e595

10 files changed

Lines changed: 84 additions & 11 deletions

File tree

_includes/developing-flows-toc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<li {% if page.url == "/docs/developing-flows/implementation" %}class="active"{% endif %}><a href="/docs/developing-flows/implementation">Implementation</a></li>
99
<li {% if page.url == "/docs/developing-flows/readability" %}class="active"{% endif %}><a href="/docs/developing-flows/readability">Readability</a></li>
1010
<li {% if page.url == "/docs/developing-flows/multiple-developers" %}class="active"{% endif %}><a href="/docs/developing-flows/multiple-developers">Project</a></li>
11-
<li {% if page.url == "/docs/developing-flows/non-functional" %}class="active"{% endif %}><a href="/docs/developing-flows/non-functional">Strict non-functional requirements</a></li>
11+
<li {% if page.url == "/docs/developing-flows/non-functional" %}class="active"{% endif %}><a href="/docs/developing-flows/non-functional">Non-functional requirements</a></li>
1212
</ul>
1313
</li>
1414
</ul>
137 KB
Loading
1.72 KB
Loading
1.63 KB
Loading
1.89 KB
Loading
54.7 KB
Loading
257 KB
Loading
269 KB
Loading
1.49 KB
Loading
Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,96 @@
11
---
22
layout: docs
33
toc: developing-flows-toc.html
4-
title: Responding to strict non-functional requirements
4+
title: Responding to non-functional requirements
55
---
66

7-
*Node-RED does not strongly focus on applications with strict non-functional requirements.*
7+
{% comment %}
8+
*Node-RED does not strongly focus on applications with non-functional requirements.*
89
*However, there are cases that it is necessary to satisfy high level non-functional requirements.*
910
*This chapter explains techniques and others to satisfy non-functional requirements.*
10-
11+
{% endcomment %}
12+
1113
### Precautions due to single thread
12-
14+
15+
{% comment %}
1316
*If a node takes long time for execution, the process of the entire Node-RED instance stops.*
1417
*Therefore, it is advisable to outsource the processing with running other services.*
15-
16-
### Sequential guarantee
17-
18+
{% endcomment %}
19+
20+
Because Node.js uses a single-thread execution model, execution of the entire Node-RED instance will stall if the execution of a node takes a long time. This causes the instance to hang.
21+
Nodes whose processing is time-consuming should be executed in a different environment from Node-RED and called asynchronously.
22+
This allows you to work around the issue in which Node-RED hangs.
23+
24+
There are 2 methods to resolve. One way to call asynchronously is to use the `HTTP`node.
25+
Place processing that requires a long time on another server, and place the `HTTP in/out` nodes before and after that processing. You can call in this way, but if it takes too long, there is a possibility that the processing will time out.
26+
27+
<div style="text-align: center">
28+
<img title="Respondig to non-functional requirements" src="./images/method1.png"/>
29+
</div>
30+
31+
The second way is to use the `mqtt` node. However, due to the function of the `mqtt` node, it is necessary to install the `MQTT broker` node. You can install it by searching `node-red-contrib-mqtt-broker` at Manage pallete menu.
32+
33+
You should enter the port number and the required details in the `MQTT broker` node. And each `mqtt in` node is connected to `mqtt out` node that has same `topic` and `port`. It means you need to type the `topic` and `port` not only localhost but also other server, but you can freely control which nodes will send and receive messages.
34+
35+
<div style="text-align: center">
36+
<img title="Respondig to non-functional requirements" src="./images/method2.png"/>
37+
</div>
38+
39+
If processing is taking a long time because it is waiting for a condition to be met, we recommend that you use asynchronous programming in Node.js.
40+
41+
### Guaranteeing the order of messages
42+
43+
{% comment %}
1844
*Node - RED does not guarantee the arrival order of messages. Therefore, it is better to design related messages in a format expressing the order relation of messages. (Separated message format)*
19-
20-
<!--
45+
{% endcomment %}
46+
47+
In some cases, it may be necessary to have an orderly relationship with multiple messages, such as transaction data, sorted records, etc. However, because the order of arrival of messages to the node in Node-RED is not guaranteed, it is not possible to express the relationship between messages by the order of arrival of the messages.
48+
49+
Node-RED has inherited asynchronous nature of Node.js with which Node-RED is developed.
50+
Therefore, in Node-RED, the processing of each node is asynchronously executed after the node receives a message.
51+
52+
This means that when two or more messages arrive at a flow, the processing of the flow does not always finish in the order of arrival of the messages. By this feature, flow can handle more messages at the same time because it does not have to wait for the processing of any other message to end.
53+
54+
#### `Sort` node
55+
56+
To ensure the order of processes, a `Sort` node can be used.
57+
You can choose sorting target of `Sort` node as `msg` or `message sequence`.
58+
By setting `msg.payload`, the contents of the message are sorted alphabetically.
59+
If you set the `message sequence`, you can use `Sort` node as feature that guarantee the order of messages arrival.
60+
61+
`Sort` node expects that `msg.parts` property is contained in its `msg` that is input.
62+
`msg.parts` is added when `msg` is divided into multiple parts by `Split` node.
63+
Instead of `Split` node, you can add `msg.parts` to `msg` with other node such as `Change` node and `Function` node. In this case, you have to set following properties to each message that you want to sort.
64+
65+
|Property | |Description
66+
|:-----------------|:-|:-----------------------------------------
67+
|`msg.parts.id` | | An identifier for the group of messages
68+
|`msg.parts.index` | | The position of messages after be sorted
69+
|`msg.parts.count` | | The total number of messages to be sorted
70+
71+
<div style="text-align: center">
72+
<img title="Respondig to non-functional requirements" src="./images/add-msg.parts-change-node.png"/>
73+
</div>
74+
75+
`Sort` node waits to output messages until all messages in the group arrive. After all messages arrive at `Sort` node, `Sort` node sorts the messages according to the sort key that is specified in the setting of the `Sort` node.
76+
If you set Sort to `message sequence` and set the Key to `msg.parts.index` in the setting of `Sort` node, `Sort` node sends messages to the next node in order of key of message. This setting enables to sort messages according to order of splitted by `Split` node.
77+
However, `Sort` node only send output when the value of `msg.part.count` matches number of messages entered.
78+
79+
<div style="text-align: center">
80+
<img title="Respondig to non-functional requirements" src="./images/message-sequence.png"/>
81+
</div>
82+
83+
Because order of messages is ensured by this approach, the next node of `Sort` node can be started to process in order you expect.
84+
85+
In addition, nodes that can manipulate the order exist as follows:
86+
87+
|![switch-node](./images/switch-node.png)|Divide a group into multiple groups|
88+
|![split-node](./images/split-node.png)|Divide the data into groups|
89+
|![join-node](./images/join-node.png)|Convert to one data from group|
90+
|![batch-node](./images/batch-node.png)|Group the entered messages|
91+
|![csv-node](./images/csv-node.png)|Group CSV records|
92+
93+
{% comment %}
2194
This content was included in this wiki. However, we have determined that it is better to add this section to the other document existing. We will discuss it next time.
2295

2396
## Managing state
@@ -34,4 +107,4 @@ This section describes the policy of state management about following points.
34107
* Type of state
35108
* Maintaining flow state
36109
* Maintaining node state
37-
-->
110+
{% endcomment %}

0 commit comments

Comments
 (0)