<commit_before>const http = require('http');
const path = require('path');
const fs = require('fs');
const cluster = require('cluster');

const port = process.argv[2];

if (cluster.isMaster) { console.log('cluster is master');
  const numWorkers = require('os').cpus().length/2;
  console.log('Master cluster setting up ' + numWorkers + ' workers...');
  for (let i = 0; i < numWorkers; i += 1) {
    cluster.fork();
  }
  cluster.on('online', function (worker) {
    console.log('Worker ' + worker.process.pid + ' is online');
  });
  cluster.on('exit', function (worker, code, signal) {
    console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal);
    console.log('Starting a new worker');
    cluster.fork();
  });
} else {
  http.createServer((req, res) => {
    console.log('pid', process.pid, 'handler start, blocking CPU');
    console.log('pid', process.pid, 'unblocked, responding');
    if (req.method === 'GET' && req.url === '/html') {
      res.writeHead(200, { 'Content-Type': 'text/html' });
      fs.readFile(path.join(__dirname, 'index.html'), (err, data) => {
        res.end(data);
      });
    }
    if (req.method === 'GET' && req.url === '/') {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.end('LOOK AT ME\n Server ' + port);
    }
  }).listen(port);
  console.log('Server running on port ' + port);
}
<commit_msg>added comments and changed variable numWorkers to the length of all cpus<commit_after>const http = require('http');
const path = require('path');
const fs = require('fs');
const cluster = require('cluster');

const port = process.argv[2];

// when the server starts, it checks if the server is the master of the threads
if (cluster.isMaster) { console.log('cluster is master');
  const numWorkers = require('os').cpus().length;
  console.log('Master cluster setting up ' + numWorkers + ' workers...');
  // creates workers for threads based on threads
  for (let i = 0; i < numWorkers; i += 1) {
    cluster.fork();
  }
  // let the user know the id of the thread worker
  cluster.on('online', function (worker) {
    console.log('Worker ' + worker.process.pid + ' is online');
  });

  // when a worker dies executing code, create another
  cluster.on('exit', function (worker, code, signal) {
    console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal);
    console.log('Starting a new worker');
    cluster.fork();
  });
} else {
  // create a server
  http.createServer((req, res) => {
    console.log(`worker ${process.pid} is working`);
    // send html file on a get request
    if (req.method === 'GET' && req.url === '/html') {
      res.writeHead(200, { 'Content-Type': 'text/html' });
      fs.readFile(path.join(__dirname, 'index.html'), (err, data) => {
        res.end(data);
      });
    }
    // for when using a proxy server, state back the port the user is on
    if (req.method === 'GET' && req.url === '/') {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.end('LOOK AT ME\n Server ' + port);
    }
  }).listen(port);
  console.log('Server running on port ' + port);
}
{'fraction_non_alphanumeric': 0.184634840341448, 'fraction_numerical': 0.006006955422067657, 'mean_word_length': 3.2641509433962264, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4864010', 'n_tokens_mistral': 1012, 'n_tokens_neox': 992, 'n_words': 285}