nodejs 使用进程池实现并发 node-process-pool

https://www.npmjs.com/package/node-process-pool

https://github.com/GeniusFunny/node-process-pool

// Process pool usage example
const ProcessPool = require('node-process-pool')
const taskParams = []
for (let i = 0; i < 5000; i++) {
  taskParams[i] = [i]
}
// Create a process pool instance
const processPool = new ProcessPool({
  maxParallelProcess: 50, // Supports maximum number of process parallelism
  timeToClose: 60 * 1000, // The maximum time for a single task to be executed
  dependency: `const path = require('path')`, // task script dependencies
  workDir: __dirname, // current directory
  taskName: 'test', // task script name
  script: async function task(input) {
    console.log("input is "+input+"pid is "+process.pid)
  },
  taskParams // Need to perform the task parameter list, two-dimensional array
})
// Process pools are used to handle large scale tasks
processPool.run()

这么好的项目怎么STAR这么少,大家用不到吗?


作者:spike

分类: Nodejs

创作时间:2023-06-25

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1