
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
cluster-daemon
Advanced tools
唉,有的时候找nodejs内存泄露很麻烦,干脆写了一个守护程序,发现内存飙涨就kill掉一个worker,阻止系统崩溃。
在cluster模式下,每个worker处理完一次请求之后,会检查自己的内存占用,如果发现超过阈值,就向master发送一个自杀消息,master负责管理所有worker的自杀消息队列,每隔3秒钟从队列中取出一个,通知那个worker允许自杀,worker接收到父进程消息之后,会在下一次处理完请求之后kill掉自己,master能够监听到worker的进程关闭事件,就会立即重启一个worker了,每3秒内最多只有一个worker会被kill掉,其他worker还能保证负载。
...
for (var i = 0; i < cpuCount; i++) daemon.fork(); //使用daemon的fork方法创建worker
cluster.on('exit', function (worker) {
logger.error('Worker ' + worker.id + ' died, time: ' + Date.now());
daemon.fork();
});
daemon.start(3000); // 启动守护,检查时间是3秒(3000毫秒)
var daemon = require('cluster-daemon');
var KB = 1024;
var MB = KB * KB;
var limit = 1024 * MB; //限制占用1G内存
app.use(daemon.middleware(function(){
return process.memoryUsage().rss > limit; //超过限度就会自动kill
}));
daemon.fork();
介绍:包装过的cluster.fork()函数,用于fork当前进程,fork过程主要是给worker添加一些事件监听。 调用者:master
daemon.star(interval, onKill);
介绍:启动轮询检查worker的自杀请求 调用者:master 参数:
daemon.stop();
介绍:结束daemon.start()的轮询检查 调用者:master
daemon.middleware(check);
介绍:检查子进程健康状态的中间件 调用者:worker 参数:
FAQs
cluster daemon
The npm package cluster-daemon receives a total of 0 weekly downloads. As such, cluster-daemon popularity was classified as not popular.
We found that cluster-daemon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.