Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.