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
838 B

5 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(`API : Cluster ${worker.process.pid} connected`)
5 years ago
})
cluster.on('disconnect', function(worker) {
Logger.info(`API : Cluster ${worker.process.pid} disconnected`)
5 years ago
})
cluster.on('exit', function(worker) {
Logger.info(`API : Cluster ${worker.process.pid} is dead`)
5 years ago
// Ensuring a new cluster will start if an old one dies
cluster.fork()
})
} else {
require('./index.js')
}