geniusfunny / node-process-pool Goto Github PK
View Code? Open in Web Editor NEWa simple process pool for Node.js
License: MIT License
a simple process pool for Node.js
License: MIT License
代码大概是这样的
**const processPool = new ProcessPool({
maxParallelProcess: 50, // 支持最大进程并行数
timeToClose: 10 * 1000, // 单个任务被执行最大时长
dependency: const path = require('path'); var lib=require("./lib");var execSync = require('child_process').execSync;var config = require('./config');
, // 任务脚本依赖
workDir: __dirname, // 当前目录
taskName: 'doTwitter', // 任务脚本名称
script: async function task(workParam) {
val = workParam;
cmd = `twint -u '${val}' --since '${today} 00:00:00' ${proxy} -o ./data/${val}_${today}.json --json`;
// console.log(cmd);
execSync(cmd,{timeout:8000});
}, // 任务脚本内容
taskParams // 需要执行的任务参数列表,二维数组
});
// 创建进程池实例
// 利用进程池进行处理大规模任务
processPool.run();**
跑完了 脚本没退出
由于目前将task函数直接赋值给进程池示例的script属性,且在进程池示例中将script写入task.js,这也存在很大的问题。
例如:10个进程,50个任务,只完成44个任务;50个进程,50个任务,完成50个任务。
猜测是任务调度的时候出现了问题。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.