signalTraps.map(type => process.once(type, async () => { try { await consumer.disconnect() } finally { process.kill(process.pid, type) } }) )
start(duration = DEFAULT_DURATION) { this.session.connect(); this.session.post('Profiler.enable', () => { this.session.post('Profiler.start', () => { console.log(`start profiling server worker #${process.pid} for ${duration} ms`) setTimeout(() => this.stop(), duration); }); }); }
function masterProcess () { console.log(`Master ${process.pid} is running`) for (let i = 0; i < numCPUs; i++) { console.log(`Forking process number ${i}...`) cluster.fork() } process.exit() }
static start(port, opt) { let app = require("../config/express")(); let PORT = process.env.PORT || port || __config.port; app.listen(PORT); if (opt && opt.debug) { __.logger.info(`Application config information: => Template engine: Nunjucks => Model database: Mongodb => Theme current: Bootstrap\n`); __.logger.info(`=> Listening on port ${PORT}. Process ID: ${process.pid}`); } }
test('should use the same process as the caller does', async t => { // given const workerNodes = new WorkerNodes(fixture('process-info')); // when const result = await workerNodes.call.getPid(); // then t.is(result, process.pid); });
app.listen(3000,()=>{ console.log(`started Process ${process.pid}`); } );
stop() { this.session.post('Profiler.stop', (error, { profile }) => { if (error) throw new Error(error); const resultFileName = `./Profile-${process.pid}-${Date.now()}.cpuprofile`; fs.writeFile(resultFileName, JSON.stringify(profile), (error) => { if (error) throw new Error(error); console.log(`write profiler result to file - ${resultFileName}`) this.session.post('Profiler.disable'); this.session.disconnect(); }); }); }
function processInfo() { console.log("==> environment: " + JSON.stringify(process.env)) console.log("==> arguments: " + process.argv) console.log("==> pid: " + process.pid) console.log("==> title: " + process.title) console.log("==> uptime: " + process.uptime()) console.log("==> memory: " + JSON.stringify(process.memoryUsage())) console.log("==> cwd: " + process.cwd()) }
app.get('/',(req,res)=>{ setTimeout(()=>{ res.status(200).send(`hello from ${process.pid}`); },2000); });
static async connect(dataDir) { const storage = new Storage(dataDir, process.pid); await storage.ensureDataDirs(); return new Queuelite(storage); }
connect() { this.session.connect(); const resultFile = fs.openSync(`HeapSnapshot-${process.pid}-${Date.now()}.heapsnapshot`, 'w'); this.session.on('HeapProfiler.addHeapSnapshotChunk', ({ params: { chunk }}) => { fs.writeSync(resultFile, chunk); }); this.session.on('HeapProfiler.reportHeapSnapshotProgress', ({ params: { done, total }}) => { console.log(`heap snapshot progress: ${Math.floor(100 * (done / total))} %`); }); }
function childProcess () { console.log(`Worker ${process.pid} started and finished`) process.exit() }
function masterProcess() { console.log(`Master ${process.pid} is running`); for (let i = 0; i < numCPUs; i++) { console.log(`Forking process number ${i}...`); cluster.fork(); } cluster.on('exit', (worker, code, signal) => { console.log(`Worker ${worker.process.pid} died`); console.log(`Forking a new process...`); cluster.fork(); }); }
function masterProcess() { console.log(`Master ${process.pid} is running`); for (let i = 0; i < numCPUs; i++) { console.log(`Forking process number ${i}...`); cluster.fork(); } console.log("exiting master"); process.exit(); }
function masterProcess () { console.log(`Master ${process.pid} is running`) for (let i = 0; i < numCPUs; i++) { console.log(`Forking process number ${i}...`) cluster.fork() } }