
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
parallel-limiter
Advanced tools
A simple solution to limit parallel Node.js async calls with low performance overhead.
To parallel-limit a call to an async function or Promise asyncFunction(...) replace with:
limiter.schedule(() => asyncFunction(...params));
See below the two steps in setting up a limiter.
| Total | Limit | parallel-limit | bottleneck |
|---|---|---|---|
| 1,000 | 1,000 | 30% overhead vs no limiter | ~70x more overhead than parallel-limit |
| 1,000 | 100 | - | 10x slower than parallel-limit |
| 1,000 | 1 | (using faster retry interval) | 1.4x slower than parallel-limit |
Tested using mocked HTTP downloads and real HTTPS server with similar results.
Tests available in the test directory.
These tests show parallel-limiter has up to 70x less overhead than bottleneck
and can run up to 10x faster in a typical unit test mocked HTTP request scenario.
10 parallel requestsYou will need to run Node.js 14.x or newer (or Browser equivalent).
await calls that should be part of the same limiting criterionParallelLimiter class, e.g. from am ES Module:
import {ParallelLimiter} from 'parallel-limiter';
This is how to import from a CommonJS module:
const {ParallelLimiter} = require('parallel-limiter');
100) as follows:
const limiter = new ParallelLimiter({maxParallel: 100});
await call that is to be limited by the same limiter:
const result = await asyncFunction(...params);
with:
const result = await limiter.schedule(() => asyncFunction(...params));
Promise.allSettled functionThis package also comes with a convenience function allSettledParallelLimited
that behaves similar to
Promise.allSettled
which can be run using a specified parallel limit.
Assuming this Promise.all or Promise.allSettled based code:
const results = Promise.allSettled(task.map(async () => createAPromiseFromTask(task)));
you may add the parallel limiting behavior by importing (from an ES Module):
import {allSettledParallelLimited} from 'parallel-limiter';
or requiring (from a CommonJS modules):
const {allSettledParallelLimited} = require('parallel-limiter');
and changing the Promise.allSettled code to:
const results = allSettledParallelLimited({
jobs: task,
jobToPromise: async () => createAPromiseFromTask(task),
maxParallel: 100,
});
All promises will be run simultaneously without exceeding the
number of maxParallel promises (here 100) running at the same time.
retryMs parameter value, e.g. set to 3msretryMs parameter value, e.g. set to 200ms, e.g.
const limiter = new ParallelLimiter({maxParallel: 100, retryMs: 3});
bottleneckpackage-limiter may be used interchangeably with the bottleneck limiter.schedule() function,
allowing you to code against both packages, e.g. if you encounter issues or limitations
with one package over the other.
See the test directory for benchmark comparisons and how both packages are used.
FAQs
Limit parallel Node.js async calls with low performance overhead
We found that parallel-limiter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.