Gathering detailed insights and metrics for atlas-throttled-queue
Gathering detailed insights and metrics for atlas-throttled-queue
Gathering detailed insights and metrics for atlas-throttled-queue
Gathering detailed insights and metrics for atlas-throttled-queue
npm install atlas-throttled-queue
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
1 Stars
9 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Oct 09, 2023
Latest Version
1.0.0
Package Id
atlas-throttled-queue@1.0.0
Unpacked Size
7.20 kB
Size
3.32 kB
File Count
7
NPM Version
6.0.1
Node Version
10.1.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Async job queue that limits the rate of job execution.
npm install --save atlas-throttled-queue
I was writing a totally legal web-scraper and I didn't want to overburden my sources with a bunch of spam. This package exports a simple queue which takes a period, τ, and lets you run arbitrary jobs at a rate of 1/τ.
This example is simplified for the sake of brevity. Let's say we have a service which takes a document, gets the keywords, and then performs a Bing search of all the keywords, obtaining the top link for each keyword. We might want to do this if we want to "learn more" about the document -- maybe we recursively scrape the links, feed the new set of documents to a machine learning algorithm so it can "learn more" about the original document, then look up links for those documents, etc.
For this example, let's assume we have the following functions:
getBingResults
: looks up a phrase on bing, parses the output, and returns a list of links.getKeywords
: Filters out the stop-words from a document, returning an set of important words.upsertLink
: Upserts an obtained link to our database.1const { readFileSync } = require("fs"); 2const ThrottledQueue = require("atlas-throttled-queue"); 3const getKeywords = require("./filter-stop-words"); 4const getBingResults = require("./bing-search-client"); 5const upsertLink = require("./upsert-link") 6 7// make a queue 8const tau = 500; 9const queue = new ThrottledQueue(tau); 10 11// get our keywords 12const doc = readFileSync("./document.txt"); 13const keywords = getKeywords(doc); 14 15// run our throttled scraper, keywords.length === 20000 16for (let i = keywords.length; i--;){ 17 queue.push(() => { 18 getBingResults(keywords[i], links => { 19 const topLink = links[0]; 20 upsertLink(topLink, () => { 21 // no-op, don't care about result of write 22 }) 23 }) 24 }) 25}
In the example above, we have 20,000 search jobs, but they are run every τ milliseconds. This helps keep us under the radar and prevents us from overloading our system. Note that the throttler does not enforce any rules regarding concurrency: if each search job takes one second, then ~2 search jobs will be running at any given time. You can place queue.push
calls inside of jobs for a concurrent queue to limit the concurrency of your jobs, in addition to limiting the rate at which they are fired.
It might be interesting to implement a dynamic τ that can react to changes in API allowance. For example, we might want to slow down our jobs if we notice rate limiting headers getting close their limit. As of right now, I don't need the feature, but implementing it would not be difficult.
There's no way to capture errors or results, this queue is only for controlling flow. If you need to capture errors or results, do it at the scope you're writing your jobs in.
done
callbackUnlike atlas-concurrent-queue, there's no callback we can call when "our queue is done". I don't think it makes a ton of sense to have a callback for this, since there isn't a well-defined moment when our throttler is finished:
done
when all jobs have returned?done
when the queue has been exausted and all jobs have been executed?It doesn't seem very well-defined, but I could be wrong and I'd be open to ideas.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
Score
Last Scanned on 2025-07-07
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