Skip to content

Commit

Permalink
Add option to set maximum number of simultaneous outgoing requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pratid committed Nov 24, 2015
1 parent eaffc92 commit 3c77a25
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.rst
Expand Up @@ -221,6 +221,9 @@ The configuration used by the adapter service is optionally read from the file
# ADAPTER_BROKER_URL - The endpoint where Context Broker is listening
ADAPTER_BROKER_URL=http://127.0.0.1:1026/

# ADAPTER_MAX_REQUESTS - Maximum number of simultaneous requests
ADAPTER_MAX_REQUESTS=5

# ADAPTER_RETRIES - Maximum number of retries invoking Context Broker
ADAPTER_RETRIES=2

Expand All @@ -234,6 +237,7 @@ Most of these attributes map to options of the `command line interface
- ``ADAPTER_UDP_ENDPOINTS`` maps to ``-u`` or ``--udpEndpoints`` option
- ``ADAPTER_PARSERS_PATH`` maps to ``-P`` or ``--parsersPath`` option
- ``ADAPTER_BROKER_URL`` maps to ``-b`` or ``--brokerUrl`` option
- ``ADAPTER_MAX_REQUESTS`` maps to ``-m`` or ``--maxRequests`` option
- ``ADAPTER_RETRIES`` maps to ``-r`` or ``--retries`` option

Default values are found in ``/opt/fiware/ngsi_adapter/lib/common.js``.
Expand Down
2 changes: 2 additions & 0 deletions doc/manuals/admin/README.rst
Expand Up @@ -172,6 +172,8 @@ You can use these command line options (available typing ``adapter --help``):
Colon-separated path with directories to look for parsers
-b, --brokerUrl
The URL of the Context Broker instance to publish data to
-m, --maxRequests
Maximum number of simultaneous outgoing requests to Context Broker
-r, --retries
Number of times a request to Context Broker is retried, in case of error

Expand Down
1 change: 1 addition & 0 deletions ngsi_adapter/README.rst
Expand Up @@ -24,6 +24,7 @@ Changelog

Version 1.3.0

- Add option to set maximum number of simultaneous outgoing requests
- Add an option to specify a list of directories to look for parsers
- Add support to UDP requests

Expand Down
3 changes: 2 additions & 1 deletion ngsi_adapter/script/build/files/debian/changelog
@@ -1,8 +1,9 @@
fiware-monitoring-ngsi-adapter (1.3.0) precise; urgency=low
* Add option to set maximum number of simultaneous outgoing requests
* Add an option to specify a list of directories to look for parsers
* Add support to UDP requests

-- Telefónica I+D <opensource@tid.es> Fri, 20 Nov 2015 18:00:00 +0200
-- Telefónica I+D <opensource@tid.es> Tue, 24 Nov 2015 18:00:00 +0200

fiware-monitoring-ngsi-adapter (1.2.4) precise; urgency=low

Expand Down
3 changes: 3 additions & 0 deletions ngsi_adapter/script/build/files/debian/ngsi_adapter.default
Expand Up @@ -18,5 +18,8 @@ ADAPTER_PARSERS_PATH=lib/parsers/nagios
# ADAPTER_BROKER_URL - The endpoint where Context Broker is listening
ADAPTER_BROKER_URL=http://127.0.0.1:1026/

# ADAPTER_MAX_REQUESTS - Maximum number of simultaneous requests
ADAPTER_MAX_REQUESTS=5

# ADAPTER_RETRIES - Maximum number of retries invoking Context Broker
ADAPTER_RETRIES=2
Expand Up @@ -18,5 +18,8 @@ ADAPTER_PARSERS_PATH=lib/parsers/nagios
# ADAPTER_BROKER_URL - The endpoint where Context Broker is listening
ADAPTER_BROKER_URL=http://127.0.0.1:1026/

# ADAPTER_MAX_REQUESTS - Maximum number of simultaneous requests
ADAPTER_MAX_REQUESTS=5

# ADAPTER_RETRIES - Maximum number of retries invoking Context Broker
ADAPTER_RETRIES=2
Expand Up @@ -187,7 +187,8 @@ if [ $1 -eq 0 ]; then
fi

%changelog
* Fri Nov 20 2015 Telefónica I+D <opensource@tid.es> 1.3.0-1
* Tue Nov 24 2015 Telefónica I+D <opensource@tid.es> 1.3.0-1
- Add option to set maximum number of simultaneous outgoing requests
- Add an option to specify a list of directories to look for parsers
- Add support to UDP requests

Expand Down
5 changes: 5 additions & 0 deletions ngsi_adapter/src/config/options.js
Expand Up @@ -38,6 +38,7 @@ var defaults = require('../lib/common').defaults;
* @property {Number} opts.listenPort Adapter listen HTTP port.
* @property {String} opts.udpEndpoints Comma-separated list of UDP endpoints (host:port:parser).
* @property {String} opts.parsersPath Colon-separated path with directories to look for parsers.
* @property {Number} opts.maxRequests Maximum number of simultaneous outgoing requests.
* @property {Number} opts.retries Maximum number of Context Broker invocation retries.
*/
var opts = require('optimist')
Expand Down Expand Up @@ -65,6 +66,10 @@ var opts = require('optimist')
alias: 'brokerUrl',
'default': process.env['ADAPTER_BROKER_URL'] || defaults.brokerUrl,
describe: 'Context Broker URL'
}).options('m', {
alias: 'maxRequests',
'default': process.env['ADAPTER_MAX_REQUESTS'] || defaults.maxRequests,
describe: 'Maximum simultaneous requests'
}).options('r', {
alias: 'retries',
'default': process.env['ADAPTER_RETRIES'] || defaults.retries,
Expand Down
6 changes: 6 additions & 0 deletions ngsi_adapter/src/lib/adapter.js
Expand Up @@ -41,6 +41,12 @@ var http = require('http'),
opts = require('../config/options');


/**
* Restrict the number of simultaneous outgoing requests.
*/
http.globalAgent.maxSockets = opts.maxRequests;


/**
* Asynchronously process incoming requests and then invoke updateContext() on ContextBroker.
*
Expand Down
2 changes: 2 additions & 0 deletions ngsi_adapter/src/lib/common.js
Expand Up @@ -43,6 +43,7 @@ exports.txIdHttpHeader = 'txId';
* @property {Number} defaults.listenPort Default adapter HTTP listen port.
* @property {String} defaults.udpEndpoints Default list of UDP endpoints (host:port:parser).
* @property {String} defaults.parsersPath Default path with directories to look for parsers.
* @property {Number} defaults.maxRequests Default maximum number of simultaneous outgoing requests.
* @property {Number} defaults.retries Default maximum number of Context Broker invocation retries.
*/
exports.defaults = {
Expand All @@ -52,5 +53,6 @@ exports.defaults = {
listenPort: 1337,
udpEndpoints: null,
parsersPath: 'lib/parsers:lib/parsers/nagios',
maxRequests: 5,
retries: 2
};

0 comments on commit 3c77a25

Please sign in to comment.