Gathering detailed insights and metrics for concurrent-request
Gathering detailed insights and metrics for concurrent-request
Gathering detailed insights and metrics for concurrent-request
Gathering detailed insights and metrics for concurrent-request
npm install concurrent-request
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
9 Commits
3 Watching
2 Branches
1 Contributors
Updated on 23 Mar 2018
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
1,300%
14
Compared to previous day
Last week
66.7%
20
Compared to previous week
Last month
-5%
76
Compared to previous month
Last year
15.5%
1,867
Compared to previous year
1
Simple request pooling with backoff strategies and jitter.
1const Pool = require('concurrent-request') 2const opts = { 3 interval: (count) => Math.pow(2, count) * 1000, // exponentional backoff 4 jitter: 1000, // 1 second range of jitter (+/- .5 seconds) 5 size: 5, // At most 5 active connections 6 tries: 5, // Give up after retrying 5 times 7 handler: function (e, resp, body, cb) { 8 if(e) { return cb(e); } // Retry if connection fails 9 if(resp.code === 429) { return cb(new Error('rate limited')); } // retry 10 return cb(null); // The request succeeded 11 } 12} 13var request = new Pool(opts); 14 15request({ uri: 'http://example.foo', method: 'GET', json: true }, function (e, body) { 16 if(e) { 17 return e.forEach((err) => console.error(err)); 18 } 19 console.log(JSON.stringify(body)); 20});
var request = new Pool(opts)
Create a new pool of request handlers. This pool will limit the number of concurrent requests made through the pool, along with retrying failed requests with backoff and jitter, making your application super friendly to remote APIs.
opts
is required and is an object of the form:
1{ 2 jitter: Number, // See below for more information 3 size: Number, // The maximum number of concurrent requests 4 tries: Number, // 5 interval: Function, // See below for more information 6 handler: Function, // See below for more information 7}
interval
- A function that computes the number of milliseconds to wait before retrying a request. For example (count) => Math.pow(2, count) * 1000
would retry after 2 seconds, then 4, then 8, then 16, and so on. This defaults to () => 0
(retry immediately).jitter
- A number that determines the amount of random jitter to apply to the retry interval. If you specify 1000
for example, you will end up with +/- 500ms. The reason for this is to prevent all size
of your concurrent requests from failing and retrying at the same exact time putting strain on the API endpoint you are hitting. The algorithm used to compute the jitter is: interval + jitter * (Math.random() - .5)
. This value will default to 0
(which means no jitter).size
- The maximum number of concurrent requests. Defaults to Infinity
.handler
- A function that determines when the library should attempt to retry. This method signature should be: function (e, resp, body, cb)
where e
, resp
, and body
are the values received from request
and the cb
is an error first callback. If you invoke the callback with an error, the library will retry the request. Otherwise it will treat the request as succesful. Defaults to () => cb(e)
tries
- The number of times this library should re-attempt a request. Defaults to 0
.request(opts, function callback(e, resp, body) {})
This method accepts an opts
object, which is the same exact opts
accepted by the request module itself.
When invoked, this function will queue the request. When the number of concurrent requests drops below the size
threshold specified in the constructor, the library will work through this queue.
Once the request has either failed tries
times or completed, callback
will be invoked. If the request failed, e
will be an array of all errors returned by the handler. Otherwise resp
and body
will be the same as you would get from the request
library.
Note: we do not support any other way of invoking the underlying
request
object at this time. Streams are not supported.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More