本文整理汇总了TypeScript中cluster.fork函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fork函数的具体用法?TypeScript fork怎么用?TypeScript fork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fork函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: spawnWorker
export function spawnWorker () {
let worker = cluster.fork();
if (!memshared.store['workerIds']) {
memshared.store['workerIds'] = [];
}
// push worker id to shared workers list.
memshared.store['workerIds'].push(worker.process.pid);
// push worker to workers list
workers.push(worker);
enableProcessCommunication(worker);
// auto-spawn a new worker on failure
worker.on("exit", () => {
console.warn("worker", process.pid, "died. Respawn.")
// remove workerId from shared store
spliceOne(memshared.store['workerIds'], memshared.store['workerIds'].indexOf(process.pid));
// remove worker from workers list.
spliceOne(workers, workers.indexOf(worker));
// spawn new worker as a replacement for this one
spawnWorker();
});
return worker;
}
开发者ID:truonglvx,项目名称:colyseus,代码行数:31,代码来源:Master.ts
示例2: forkListenerProcesses
private static forkListenerProcesses (numberOfCores: number): void {
for (let i = 0; i < numberOfCores; i++) {
cluster.fork()
}
cluster.on('exit', (worker, code, signal) => {
logger.info(`Worker ${worker.process.pid} exited with ${code ? code : signal}`)
})
}
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:8,代码来源:applicationCluster.ts
示例3: crawl
/**
* Start crawling
*/
protected async crawl(): Promise<void> {
await this.crawlUrl(this.getStartingUrl(), this.worker);
for (let i = 1; i < numCPUs; i++) {
cluster.fork();
}
await this.crawlUrlData();
}
开发者ID:chen-framework,项目名称:crawler,代码行数:12,代码来源:page.ts
示例4: spawnMore
function spawnMore() {
let worker;
if (options.worker) {
worker = child.fork(options.worker, options.workerArgs);
log.debug("Spawning worker %s as child process: %j %j",
pid(worker), options.worker, options.workerArgs);
} else {
worker = cluster.fork();
log.debug("Spawning worker in cluster:", pid(worker));
}
startTimes[pid(worker)] = Date.now();
if (!options.worker) {
worker.on("listening", (addr) =>
log.info("Process", pid(worker), "is now listening on",
addr.address + ":" + addr.port));
}
// Enable Erlang mode
worker.on("exit", (code, signal) => {
const lifetime = Date.now() - startTimes[pid(worker)];
let replacement;
delete startTimes[pid(worker)];
if (worker.suicide) {
log.info("Worker", pid(worker), "terminated voluntarily.");
return;
}
log.info("Process", pid(worker), "terminated with signal", signal,
"code", code + "; restarting.");
if (lifetime < options.failureThreshold) {
failures++;
} else {
failures = 0;
}
if (failures > options.retryThreshold) {
log.warn(failures + " consecutive failures; pausing for",
options.retryDelay + "ms before respawning.");
}
setTimeout(() => {
replacement = spawnMore();
replacement.on("online", () =>
log.info("Process", replacement.process.pid,
"has successfully replaced", pid(worker)));
}, (failures > options.retryThreshold) ? options.retryDelay : 0);
});
return worker;
}
开发者ID:bodil,项目名称:hellojoe,代码行数:53,代码来源:hellojoe.ts
示例5: function
cluster.on( 'exit', function( deadWorker, code, signal ) {
const worker = cluster.fork();
// Note the process IDs
const newPID = worker.process.pid;
const oldPID = deadWorker.process.pid;
console.log( `Cluster ${worker.process.pid} died` );
console.log( `Attempting to restart failed cluster` );
// Log the event
console.log( `worker ${oldPID} died` );
console.log( `worker ${newPID} born` );
});
开发者ID:MKHenson,项目名称:noxy,代码行数:14,代码来源:main.ts
示例6: forkOne
function forkOne(){
let worker = cluster.fork();
worker.send({
config,
clientConfig,
flags
});
worker.on('disconnect', () => {
worker.kill('SIGTERM');
forkOne();
});
}
开发者ID:raelgor,项目名称:zen-arena,代码行数:14,代码来源:app.ts
示例7: createWorkers
async function createWorkers(serverName: string, queueName: string): Promise<cluster.Worker[]> {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
return new Promise<cluster.Worker[]>(((resolve, reject) => {
const onlineWorkers: cluster.Worker[] = [];
cluster.on('online', (worker: cluster.Worker) => {
onlineWorkers.push(worker);
if (onlineWorkers.length === numCPUs) {
resolve(onlineWorkers);
}
});
}));
}
开发者ID:swanest,项目名称:micromessaging,代码行数:14,代码来源:Master.ts
示例8: main
async function main() {
if (cluster.isMaster) {
// tslint:disable-next-line
console.log(`Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on("exit", (worker, code, signal) => {
// tslint:disable-next-line
console.log(`worker ${worker.process.pid} died`);
});
} else {
const db = await dbClient.connect();
Container.set(Db, db);
// Workers can share any TCP connection
// In this case it is an HTTP server
const playground = {
settings: {
"editor.cursorShape": "line",
} as any,
};
const server = new ApolloServer({
schema,
playground,
});
server.listen(config.PORT, () =>
// tslint:disable-next-line
console.log(
`Dictionary service is running on http://localhost:${
config.PORT
}`,
),
);
// tslint:disable-next-line
console.log(`Worker ${process.pid} started`);
}
}
开发者ID:vnenkpet,项目名称:japanese,代码行数:44,代码来源:index.ts
示例9: spawn
/**
* Spawn workers
*/
function spawn(callback: any): void {
// Count the machine's CPUs
const cpuCount = os.cpus().length;
const progress = new ProgressBar(cpuCount, 'Starting workers');
// Create a worker for each CPU
for (let i = 0; i < cpuCount; i++) {
const worker = cluster.fork();
worker.on('message', message => {
if (message === 'ready') {
progress.increment();
}
});
}
// On all workers started
progress.on('complete', () => {
callback();
});
}
开发者ID:syuilo,项目名称:misskey-core,代码行数:24,代码来源:index.ts
示例10: clusterFork
const spawn = () => {
const worker = clusterFork(env);
remoteBus.target = createProcessBus(family, worker, localBus);
worker.on("disconnect", () => {
remoteBus.target = undefined;
// add timeout in case the worker is crashing repeatedly
setTimeout(spawn, 1000);
});
};
开发者ID:cryptobuks,项目名称:tandem,代码行数:11,代码来源:node.ts
注:本文中的cluster.fork函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论