Skip to content

Commit 91e872f

Browse files
authored
Merge pull request #65 from telefonicaid/feature/cluster-support-prelanding
Update IoTA-Sigfox with the changes of the IoTA Node Lib related to multi-threading (final landing)
2 parents 27f9fb0 + 6f54236 commit 91e872f

File tree

11 files changed

+566
-9
lines changed

11 files changed

+566
-9
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
- ADD PM2_ENABLED flag to Docker
2-
- Upgrade NodeJS version from 8.16.0 to 8.16.1 in Dockerfile due to security issues
1+
- ADD PM2_ENABLED flag to Docker.
2+
- Upgrade NodeJS version from 8.16.0 to 8.16.1 in Dockerfile due to security issues.
3+
- Update sigfox-test.js to show the status of the response after send a message.
4+
- Improve MandatoryFieldsNotFound function (errors.js) in order to incorporate which mandatory fields is
5+
not found.
6+
- Improve in requiredFields function (sigfoxHandlers.js) in order to know the exactly field that it is not
7+
provided.
8+
- NOTE: in the "upgrade iotagent-node-lib from X to Y" include a mention to configure multithreading using cluster
9+
nodejs module (through multiCore config.js parameter or IOTA_MULTI_CORE environment variable).

bin/iotagent-sigfox

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
'use strict';
2626

2727
var iotAgent = require('../lib/iotagentCore'),
28+
iotAgentLib = require('iotagent-node-lib'),
29+
info = require('../package.json'),
2830
context = {
2931
op: 'IoTAgentSIGFOX.Executable'
3032
},
@@ -39,7 +41,9 @@ function start() {
3941
config = require('../config');
4042
}
4143

42-
iotAgent.start(config, function (error) {
44+
config.iota.iotaVersion = info.version;
45+
46+
iotAgentLib.startServer(config, iotAgent, function (error) {
4347
if (error) {
4448
logger.error(context, 'Error starting Sigfox IoT Agent: [%s] Exiting process',
4549
JSON.stringify(error));

bin/sigfox-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ function sendMeasure(commands) {
5757
console.log('\nError sending data to the Sigfox IoT Agent: ' + error);
5858
} else {
5959
console.log('\nData successfully sent');
60+
61+
// Now, we analyse the response obtained in the call
62+
console.log('Response Code [%d]: [%s]', response.statusCode, JSON.parse(body)['message']);
6063
}
6164

6265
clUtils.prompt();

config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ config.iota = {
135135

136136
/**
137137
* Configuration for the IoT Manager. If the IoT Agent is part of a configuration composed of multiple IoTAgents
138-
* coordinated by an IoT Manager, this section defines the information that will be used to connect with that manager.
138+
* coordinated by an IoT Manager, this section defines the information that will be used to connect with that
139+
* manager.
139140
*/
140141
iotManager: {
141142
/**
@@ -252,4 +253,10 @@ config.iota = {
252253
*/
253254
config.defaultKey = 'TEF';
254255

256+
/**
257+
* flag indicating whether the node server will be executed in multi-core option (true) or it will be a
258+
* single-thread one (false).
259+
*/
260+
//config.multiCore = false;
261+
255262
module.exports = config;

docker/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,42 @@ Currently, this `_FILE` suffix is supported for:
180180
- `IOTA_AUTH_PASSWORD`
181181
- `IOTA_AUTH_CLIENT_ID`
182182
- `IOTA_AUTH_CLIENT_SECRET`
183+
184+
## Best Practices
185+
186+
### Increase ULIMIT in Docker Production Deployments
187+
188+
Default settings for ulimit on a Linux system assume that several users would share the system. These settings limit the
189+
number of resources used by each user. The default settings are generally very low for high performance servers and
190+
should be increased. By default, we recommend, that the SigFox IoTAgent server in high performance scenarios, the
191+
following changes to ulimits:
192+
193+
```console
194+
ulimit -n 65535 # nofile: The maximum number of open file descriptors (most systems do not allow this
195+
value to be set)
196+
ulimit -c unlimited # core: The maximum size of core files created
197+
ulimit -l unlimited # memlock: The maximum size that may be locked into memory
198+
```
199+
200+
If you are just doing light testing and development, you can omit these settings, and everything will still work.
201+
202+
To set the ulimits in your container, you will need to run SigFox IoTAgent Docker containers with the following
203+
additional --ulimit flags:
204+
205+
```console
206+
docker run --ulimit nofile=65535:65535 --ulimit core=100000000:100000000 --ulimit memlock=100000000:100000000 \
207+
--name iotagent -d fiware/sigfox-iotagent
208+
```
209+
210+
Since “unlimited” is not supported as a value, it sets the core and memlock values to 100 GB. If your system has more
211+
than 100 GB RAM, you will want to increase this value to match the available RAM on the system.
212+
213+
> Note: The --ulimit flags only work on Docker 1.6 or later.
214+
215+
Nevertheless, you have to "request" more resources (i.e. multiple cores), which might be more difficult for orchestrates
216+
([Docker Engine](https://docs.docker.com/engine) or [Kubernetes](https://kubernetes.io)) to schedule than a few
217+
different containers requesting one core (or less...) each (which it can, in turn, schedule on multiple nodes, and not
218+
necessarily look for one node with enough available cores).
219+
220+
If you want to get more details about the configuration of the system and node.js for high performance scenarios, please
221+
refer to the [Installation Guide](https://iotagent-sigfox.readthedocs.io/en/latest/installationguide/index.html).

docs/installationguide.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Installation & Administration Guide
2+
3+
- [Installation](#installation)
4+
- [High performance configuration usage](#high-performance-configuration-usage)
5+
16
## Installation
27

38
The Sigfox IoT Agent can be installed in two ways: cloning the GitHub repository, or using Docker.
@@ -26,3 +31,147 @@ Sigfox IoT Agent:
2631
```bash
2732
docker run -t -i --link orion:orion -p 4041:4041 -p 17428:17428 fiware/sigfox-iotagent
2833
```
34+
35+
## High performance configuration usage
36+
37+
Node.js is single‑threaded and uses non-blocking I/O, allowing it to scale up to tens of thousands of concurrent
38+
operations. Nevertheless, Node.js has a few weak points and vulnerabilities that can make Node.js‑based systems to offer
39+
under-performance behaviour, specially when a Node.js web application experiences rapid traffic growth.
40+
41+
Additionally, It is important to know the place in which the node.js server is running, because it has limitations.
42+
There are two types of limits on the host: hardware and software. Hardware limits can be easy to spot. Your application
43+
might be consuming all of the memory and needing to consume disk to continue working. Adding more memory by upgrading
44+
your host, whether physical or virtual, seems to be the right choice.
45+
46+
Moreover, Node.js applications have also a software memory limit (imposed by V8), therefore we cannot forget about these
47+
limitations when we execute a service. In this case of 64-bit environment, your application would be running by default
48+
at a 1 GB V8 limit. If your application is running in high traffic scenarios, you will need a higher limit. The same is
49+
applied to other parameters.
50+
51+
It means that we need to make some changes in the execution of node.js and in the configuration of the system:
52+
53+
- **Node.js flags**
54+
55+
- **--use-idle-notification**
56+
57+
Turns of the use idle notification to reduce memory footprint.
58+
59+
- **--expose-gc**
60+
61+
Use the expose-gc command to enable manual control of the garbage collector from the own node.js server code. In
62+
case of the IoTAgent, it is not implemented because it is needed to implement the calls to the garbage collector
63+
inside the ser server, nevertheless the recommended value is every 30 seconds.
64+
65+
- **--max-old-space-size=xxxx**
66+
67+
In that case, we want to increase the limit for heap memory of each V8 node process in order to use max capacity
68+
that it is possible instead of the 1,4Gb default on 64-bit machines (512Mb on a 32-bit machine). The
69+
recommendation is at least to use half of the total memory of the physical or virtual instance.
70+
71+
- **User software limits**
72+
73+
Linux kernel provides some configuration about system related limits and maximums. In a distributed environment with
74+
multiple users, usually you need to take into control the resources that are available for each of the users.
75+
Nevertheless, when the case is that you have only one available user but this one request a lot of resources due to
76+
a high performance application the default limits are not proper configured and need to be changed to resolve the
77+
high performance requirements. These are like maximum file handler count, maximum file locks, maximum process count
78+
etc.
79+
80+
You can see the limits of your system executing the command:
81+
82+
```bash
83+
ulimit -a
84+
```
85+
86+
You can define the corresponding limits inside the file limits.conf. This description of the configuration file
87+
syntax applies to the `/etc/security/limits.conf` file and \*.conf files in the `/etc/security/limits.d` directory.
88+
You can get more information about the limits.conf in the
89+
[limits.con - linux man pages](http://man7.org/linux/man-pages/man5/limits.conf.5.html). The recommended values to
90+
be changes are the following:
91+
92+
- **core**
93+
94+
Limits of the core file size in KB, we recommend to change to `unlimited` both hard and soft types.
95+
96+
* soft core unlimited
97+
* hard core unlimited
98+
99+
- **data**
100+
101+
Maximum data size in KB, we recommend to change to `unlimited` both hard and soft types.
102+
103+
* soft data unlimited
104+
* hard data unlimited
105+
106+
- **fsize**
107+
108+
Maximum filesize in KB, we recommend to change to `unlimited` both hard and soft types.
109+
110+
* soft fsize unlimited
111+
* hard fsize unlimited
112+
113+
- **memlock**
114+
115+
Maximum locked-in-memory address space in KB, we recommend to change to `unlimited` both hard and soft types.
116+
117+
* memlock unlimited
118+
* memlock unlimited
119+
120+
- **nofile**
121+
122+
Maximum number of open file descriptors, we recommend to change to `65535` both hard and soft types.
123+
124+
* soft nofile 65535
125+
* hard nofile 65535
126+
127+
- **rss**
128+
129+
Maximum resident set size in KB (ignored in Linux 2.4.30 and higher), we recommend to change to `unlimited` both
130+
hard and soft types.
131+
132+
* soft rss unlimited
133+
* hard rss unlimited
134+
135+
- **stack**
136+
137+
Maximum stack size in KB, we recommend to change to `unlimited` both hard and soft types.
138+
139+
* soft stack unlimited
140+
* hard stack unlimited
141+
142+
- **nproc**
143+
144+
Maximum number of processes, we recommend to change to `unlimited` both hard and soft types.
145+
146+
* soft nproc unlimited
147+
* hard nproc unlimited
148+
149+
You can take a look to the [limits.conf](limits.conf) file provided in this folder with all the values provided.
150+
151+
- **Configure kernel parameters**
152+
153+
sysctl is used to modify kernel parameters at runtime. We plan to modify the corresponding `/etc/sysctl.conf` file.
154+
You can get more information in the corresponding man pages of
155+
[sysctl](http://man7.org/linux/man-pages/man8/sysctl.8.html) and
156+
[sysctl.conf](http://man7.org/linux/man-pages/man5/sysctl.conf.5.html). You can search all the kernel parameters by
157+
using the command `sysctl -a`
158+
159+
- **fs.file-max**
160+
161+
The maximum file handles that can be allocated, the recommended value is `1000000`.
162+
163+
fs.file-max = 1000000
164+
165+
- **fs.nr_open**
166+
167+
Max amount of file handles that can be opened, the recommended value is `1000000`.
168+
169+
fs.nr_open = 1000000
170+
171+
- **net.netfilter.nf_conntrack_max**
172+
173+
Size of connection tracking table. Default value is nf_conntrack_buckets value \* 4.
174+
175+
net.nf_conntrack_max = 1048576
176+
177+
For more details about any other kernel parameters, take a look to the example [sysctl.conf](sysctl.conf) file.

docs/limits.conf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### USER LIMITS TUNING ###
2+
3+
# Maximum number of open file descriptors
4+
* soft nofile 65535
5+
* hard nofile 65535
6+
7+
# Maximum number of processes
8+
* soft nproc unlimited
9+
* hard nproc unlimited
10+
11+
# Maximum filesize in KB
12+
* soft fsize unlimited
13+
* hard fsize unlimited
14+
15+
# Maximum data size in KB
16+
* soft data unlimited
17+
* hard data unlimited
18+
19+
# Maximum stack size in KB
20+
* soft stack unlimited
21+
* hard stack unlimited
22+
23+
# Maximum resident set size in KB (ignored in Linux 2.4.30 and higher)
24+
* soft rss unlimited
25+
* hard rss unlimited
26+
27+
# Limits of the core file size in KB
28+
* soft core unlimited
29+
* hard core unlimited
30+
31+
# Maximum locked-in-memory address space in KB
32+
* memlock unlimited
33+
* memlock unlimited

0 commit comments

Comments
 (0)