【已解决】一个console.log不打印的问题
发布于 11 年前 作者 yuanxiaolong 22492 次浏览 最后一次编辑是 8 年前

初学node,请教个问题。 问题:console.log(‘start’); 这行为什么没有打印出来?。。。。。。eclipse的IDE没显示,命令行就显示了 源码如下:

var cluster = require(‘cluster’); var http = require(‘http’); var numCPUs = require(‘os’).cpus().length;

var rssWarn = (50 * 1024 * 1024),heapWarn = (50 * 1024 * 1024);

var workers = {};

if (cluster.isMaster) { for (var i = 0; i < numCPUs; i++) { createWorker(); } setInterval(function(){ var time = new Date().getTime(); for (var pid in workers) { if (workers.hasOwnProperty(pid) && workers[pid].lastCb + 5000 < time) { console.log(‘Long running worker ’ + pid + ’ killed’); workers[pid].worker.kill(); delete workers[pid]; createWorker(); } } },1000); }else{ //服务器 http.Server(function(req,res){ if (Math.floor(Math.random() * 10) === 4) {//十分之一的概率 console.log(‘Stopped ’ + process.pid + ’ form ever finishinga’); console.log(‘start’);//我本地eclipseIDE估计环境问题,导致这行没打印出来。 while(true){continue;} console.log(‘end’); } res.writeHead(200); res.end('hello world form ’ + process.pid + ‘\n’); }).listen(8000); setInterval(function report(){ process.send({cmd:“reportMem”,memory:process.memoryUsage(),process: process.pid}); },1000); }

function createWorker(){ var worker = cluster.fork(); console.log('Created worker: ’ + worker.process.pid); workers[worker.process.pid] = {worker:worker,lastCb: new Date().getTime() - 1000}; worker.on(‘message’,function(m){ if (m.cmd === “reportMem”) { workers[m.process].lastCb = new Date().getTime(); if (m.memory.rss > rssWarn) { console.log(‘worker ’ + m.process + ’ using too much memory’); } } }); }

回到顶部