<commit_before>'use strict';

/**
 * Libraries
 **/
var cluster = require('cluster');
var datefmt = require('dateformat');

/**
 * Setup
 **/
var workers = parseInt(process.env.CLUSTER_WORKERS || 2, 10);

cluster.setupMaster({exec : "app.js"});

/**
 * Utilities
 **/
var restartCount = 0;

function say(message) {
    console.log("[SERVER] " + message);
}

function checkRestart() {
    if (restartCount >= 8) {
        say("FATAL: Too many restarts in too short a time.");
        process.exit(1);
    }
    restartCount = 0;
}
setInterval(checkRestart, 2000);

/**
 * Startup Messaging
 **/
say("Master starting:");
say("time        => " + datefmt(new Date(), "ddd, dd mmm yyyy hh:MM:ss Z"));
say("pid         => " + process.pid);
say("environment => " + process.env.NODE_ENV);

/**
 * Fork Workers
 **/
say("Workers starting:");

for (var i = 0; i < workers; i += 1) {
    cluster.fork();
}

/**
 * Worker Event Handlers
 **/
cluster.on('exit', function (worker) {
    say('worker      => with pid: ' +
        worker.process.pid +
        ', died. Restarting...');
    restartCount++;
    cluster.fork();
});

cluster.on('online', function (worker) {
    say('worker      => start with pid: ' + worker.process.pid + '.');
});
// vim: ft=javascript sw=4 sts=4 et:<commit_msg>Don't use a hardcoded core number.<commit_after>'use strict';

/**
 * Libraries
 **/
var cluster = require('cluster');
var datefmt = require('dateformat');
var os = require('os');

/**
 * Setup
 **/
var numOfCores = os.cpus().length / 2;
var workers = parseInt(process.env.CLUSTER_WORKERS || numOfCores, 10);

cluster.setupMaster({ exec : "app.js" });

/**
 * Utilities
 **/
var restartCount = 0;

function say(message) {
    console.log("[SERVER] " + message);
}

function checkRestart() {
    if (restartCount >= 8) {
        say("FATAL: Too many restarts in too short a time.");
        process.exit(1);
    }
    restartCount = 0;
}
setInterval(checkRestart, 2000);

/**
 * Startup Messaging
 **/
say("Master starting:");
say("time        => " + datefmt(new Date(), "ddd, dd mmm yyyy hh:MM:ss Z"));
say("pid         => " + process.pid);
say("environment => " + process.env.NODE_ENV);

/**
 * Fork Workers
 **/
say("Workers starting:");

for (var i = 0; i < workers; i += 1) {
    cluster.fork();
}

/**
 * Worker Event Handlers
 **/
cluster.on('exit', function (worker) {
    say('worker      => with pid: ' +
        worker.process.pid +
        ', died. Restarting...');
    restartCount++;
    cluster.fork();
});

cluster.on('online', function (worker) {
    say('worker      => start with pid: ' + worker.process.pid + '.');
});

// vim: ft=javascript sw=4 sts=4 et:
{'fraction_non_alphanumeric': 0.19706103993971363, 'fraction_numerical': 0.011303692539562924, 'mean_word_length': 3.053435114503817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '439031', 'n_tokens_mistral': 938, 'n_tokens_neox': 912, 'n_words': 214}