Repository navigation
cluster: Worker based implementation? #37449
Copy link
Copy link
Closed as not planned
Labels
clusterIssues and PRs related to the cluster subsystem.Issues and PRs related to the cluster subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Activity
- addedclusterIssues and PRs related to the cluster subsystem.Issues and PRs related to the cluster subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.
on Feb 20, 2021 const { Worker, isMainThread, parentPort, workerData } = require('worker_threads'); const http = require('http'); if (isMainThread) { // This is the main thread (master process). const numWorkers = 4; const workers = []; // Create worker threads. for (let i = 0; i < numWorkers; i++) { const worker = new Worker(__filename, { workerData: { workerId: i } }); workers.push(worker); } // Create a simple HTTP server to distribute requests. const server = http.createServer((req, res) => { // Distribute incoming HTTP requests among workers. const worker = workers[Math.floor(Math.random() * numWorkers)]; worker.postMessage(req.url); }); server.listen(3000, () => { console.log('Server is running on port 3000'); }); } else { // This is a worker thread. const workerId = workerData.workerId; parentPort.on('message', (url) => { // Handle the request in the worker thread. console.log(`Worker ${workerId} processing request for URL: ${url}`); // Simulate some work (e.g., processing the request). setTimeout(() => { console.log(`Worker ${workerId} finished processing request for URL: ${url}`); parentPort.postMessage(`Response from Worker ${workerId} for URL: ${url}`); }, 1000); }); }github-actions commented
on Jun 27, 2026 on Jun 27, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jun 27, 2026 github-actions commented
on Jul 28, 2026 on Jul 28, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Metadata
Metadata
Assignees
Labels
clusterIssues and PRs related to the cluster subsystem.Issues and PRs related to the cluster subsystem.questionIssues asking questions about Node.js.Issues asking questions about Node.js.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Would it make sense/be possible to re-implement/create alternative implementation for cluster that is based on
Workers instead of child processes? Would make it possible to more efficiently pass data between the parent process and workers.