<commit_before>"use strict";

const co = require('co');
const _ = require('underscore')
const nuuid = require('node-uuid');
const moment = require('moment');
const cluster = require('cluster')
const querablep = require('querablep')
const constants = require('./constants')

let clusterId = 0

if (cluster.isMaster) {

  // Super important for Node.js debugging
  const debug = process.execArgv.toString().indexOf('--debug') !== -1;
  if(debug) {
    //Set an unused port number.
    process.execArgv = [];
  }

  /**
   * Cluster controller, handles the messages between the main program and the PoW cluster.
   */
  class Master {

    constructor(nbCores, logger) {
      this.clusterId = clusterId++
      this.nbCores = nbCores
      this.logger = logger || Master.defaultLogger()
      this.currentPromise = null
      this.slaves = []
      this.slavesMap = {}
      this.conf = {}
      this.onInfoMessage = (message) => {
        this.logger.info(`${message.pow.pow} nonce = ${message.pow.block.nonce}`)
      }
    }

    get nbWorkers() {
      return this.slaves.length
    }

    get hasProofPending() {
      return !!this.currentPromise
    }

    set onInfoMessage(callback) {
      this.onInfoCallback = callback
    }

    onWorkerMessage(worker, message) {
      // this.logger.info(`worker#${this.slavesMap[worker.id].index} sent message:${message}`)
      if (message.pow && message.pow.pow) {
        this.onInfoCallback && this.onInfoCallback(message)
      }
      if (this.currentPromise && message.uuid === this.currentPromise.extras.uuid && !this.currentPromise.isResolved() && message.answer) {
        this.logger.info(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index} HAS FOUND A PROOF #${message.answer.pow.pow}`)
        this.currentPromise.extras.resolve(message.answer)
        // Stop the slaves' current work
        this.cancelWork()
      }
      this.logger.debug(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index}:`, message)
    }

    initCluster() {
      // Setup master
      cluster.setupMaster({
        exec: __filename
      })

      this.slaves = Array.from({ length: this.nbCores }).map((value, index) => {
        const worker = cluster.fork()
        this.logger.info(`Creating worker c#${this.clusterId}#w#${worker.id}`)
        this.slavesMap[worker.id] = {

          // The Node.js worker
          worker,

          // Inner identifier
          index,
<commit_msg>[fix] Remove some logs from PoW cluster<commit_after>"use strict";

const co = require('co');
const _ = require('underscore')
const nuuid = require('node-uuid');
const moment = require('moment');
const cluster = require('cluster')
const querablep = require('querablep')
const constants = require('./constants')

let clusterId = 0

if (cluster.isMaster) {

  // Super important for Node.js debugging
  const debug = process.execArgv.toString().indexOf('--debug') !== -1;
  if(debug) {
    //Set an unused port number.
    process.execArgv = [];
  }

  /**
   * Cluster controller, handles the messages between the main program and the PoW cluster.
   */
  class Master {

    constructor(nbCores, logger) {
      this.clusterId = clusterId++
      this.nbCores = nbCores
      this.logger = logger || Master.defaultLogger()
      this.currentPromise = null
      this.slaves = []
      this.slavesMap = {}
      this.conf = {}
      this.onInfoMessage = (message) => {
        this.logger.info(`${message.pow.pow} nonce = ${message.pow.block.nonce}`)
      }
    }

    get nbWorkers() {
      return this.slaves.length
    }

    get hasProofPending() {
      return !!this.currentPromise
    }

    set onInfoMessage(callback) {
      this.onInfoCallback = callback
    }

    onWorkerMessage(worker, message) {
      // this.logger.info(`worker#${this.slavesMap[worker.id].index} sent message:${message}`)
      if (message.pow && message.pow.pow) {
        this.onInfoCallback && this.onInfoCallback(message)
      }
      if (this.currentPromise && message.uuid === this.currentPromise.extras.uuid && !this.currentPromise.isResolved() && message.answer) {
        this.logger.info(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index} HAS FOUND A PROOF #${message.answer.pow.pow}`)
        this.currentPromise.extras.resolve(message.answer)
        // Stop the slaves' current work
        this.cancelWork()
      }
      // this.logger.debug(`ENGINE c#${this.clusterId}#${this.slavesMap[worker.id].index}:`, message)
    }

    initCluster() {
      // Setup master
      cluster.setupMaster({
        exec: __filename
      })

      this.slaves = Array.from({ length: this.nbCores }).map((value, index) => {
        const worker = cluster.fork()
        this.logger.info(`Creating worker c#${this.clusterId}#w#${worker.id}`)
        this.slavesMap[worker.id] = {

          // The Node.js worker
          worker,

          // Inner identifier
          index,

{'fraction_non_alphanumeric': 0.14613354982748122, 'fraction_numerical': 0.0008118530545971179, 'mean_word_length': 2.7276853252647504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7041302', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1484, 'n_words': 302}