Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I run over 500 000 uids to fetch their associated data via a promise (promiseUserData(uid)). For some reason the memory usage is not cleared from loop to loop.
Roughly 4mb of data is used per loop and is not cleared from memory.
I am ignorant as how to fix this. Promise pooling also results in this issue.
Help would be much appreciated.
Thank you
for (var i = 0; i <= numPasses; i++) {
var subset = uids.splice(0, 1000);
var userDataArray = [];
var promises = [];
subset.map((uid) => {
promises.push(promiseUserData(uid).then((userData) => {
if (userData) {
userDataArray.push(userData);
await Promise.all(promises).catch((err) => {
console.log('Error in Promises.all: ', err);
–
–
–
–
You are creating 1000 promises at once for every iteration.
I am not entirely sure what you are trying but I could imagine you are looking for something like Bluebird.map()
. It is a handy way to process a lot promises with a set concurrency. Probably you are already using splice inside of that loop in order to process your promises in batches.
This approach requires you to install and import bluebird:
const userDataArray = [];
try {
await Bluebird.map(uids, async (uid) => {
const userData = await promiseUserData(uid);
if (userData) { userDataArray.push(userData); }
}, { concurrency: 100 })
} catch (err) {
console.log('Error in Promises.all: ', err);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.