You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
820 B
38 lines
820 B
6 years ago
|
/*!
|
||
|
* accounts/index-cluster.js
|
||
|
* Copyright © 2019 – Katana Cryptographic Ltd. All Rights Reserved.
|
||
|
*/
|
||
|
'use strict'
|
||
|
|
||
|
const os = require('os')
|
||
|
const cluster = require('cluster')
|
||
|
const Logger = require('../lib/logger')
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Launch a cluster of Samourai API
|
||
|
*/
|
||
|
const nbCPUS = os.cpus()
|
||
|
|
||
|
if (cluster.isMaster) {
|
||
|
nbCPUS.forEach(function() {
|
||
|
cluster.fork()
|
||
|
})
|
||
|
|
||
|
cluster.on('listening', function(worker) {
|
||
|
Logger.info(`Cluster ${worker.process.pid} connected`)
|
||
|
})
|
||
|
|
||
|
cluster.on('disconnect', function(worker) {
|
||
|
Logger.info(`Cluster ${worker.process.pid} disconnected`)
|
||
|
})
|
||
|
|
||
|
cluster.on('exit', function(worker) {
|
||
|
Logger.info(`Cluster ${worker.process.pid} is dead`)
|
||
|
// Ensuring a new cluster will start if an old one dies
|
||
|
cluster.fork()
|
||
|
})
|
||
|
} else {
|
||
|
require('./index.js')
|
||
|
}
|