Ich habe eine node.js -Anwendung, die mit einer PostgreSQL -Datenbank mit Millionen von Benutzern interagiert. Für eine bestimmte Funktion muss ich rund 100.000 Benutzer basierend auf einem Kriterium (z. >
Derzeit bringt meine Implementierung alle übereinstimmenden Benutzer in den Speicher und verarbeitet sie dann in Stücken wie SO: < /p>
async function processMessageForSubscribers(channelId, channelName, message, addresses) {
try {
// get around 100000 users in memory
const users = await getUsersByTrackedTelegramChannel(channelId);
const CHUNK_SIZE = 500;
const notifyTasks = [];
const autotradeTasks = [];
// Split users into chunks for parallel processing
const processUserChunk = async (userChunk) => {
await Promise.all(
userChunk.map(async (user) => {
const config = user.trackingConfig[channelId];
const autotradeAmount = config?.autotradeAmount;
if (config.newPost === 'NOTIFY') {
// Create notification tasks
createNotificationTask(user, addresses, message, channelId, channelName, autotradeAmount, notifyTasks);
}
})
);
};
// Process users in chunks
for (let i = 0; i < users.length; i += CHUNK_SIZE) {
const chunk = users.slice(i, i + CHUNK_SIZE);
await processUserChunk(chunk);
}
await queueTasks(notifyTasks, autotradeTasks);
} catch (error) {
console.error('Error processing subscribers:', error);
throw error;
}
}< /code>
< /div>
< /div>
< /p>
Meine Sorge ist, dass das Aufnehmen von 100.000 Benutzern mehr als sofort in den Speicher führen kann Auf hohe Speicherverwendung und potenziell Einflussleistung.>
Wie kann ich große PostgreSQL -Datensätze in Node.js ohne hohen Speicheraufwand effizient verarbeiten? ⇐ JavaScript
-
- Similar Topics
- Replies
- Views
- Last post