ECONNRESET when making thousands requests
In situation doing thousands of http requests, it is easy to get error ECONNRESET
, for example :
1 | require('isomorphic-fetch'); |
After few seconds, error ECONNRESET
show up like this, due to too many request processing at a time :
1 | (node:836) UnhandledPromiseRejectionWarning: FetchError: request to http://example.com/315 failed, reason: read ECONNRESET |
Set concurrency with Bluebird Promise.map
Bluebird Promise.map has a concurrency
option to deal with this issue, here is syntax from Blubird documentation :
1 | Promise.map( |
To use it, pass your Iterable item
in first parameter, Callback function receive item return promise
as second parameter, concurrency
as third parameter, for example :
1 | require('isomorphic-fetch'); |
Alternatives
You could also use es6-promise-pool, promise-limit or async/queue to deal with large amount of http requests.
Reference
http://bluebirdjs.com/docs/api/promise.map.html
https://github.com/timdp/es6-promise-pool