<commit_before>/**
 * Module dependencies.
 */
var http = require('http')
  , https = require('https')
  , cluster = require('cluster')
  , os = require('os')
  , fs = require('fs');


/**
 * Component-ized boot phase that listens for HTTP requests.
 *
 * This component provides a boot phase that starts an HTTP or HTTPS server (or
 * cluster of such servers).  The server is configured according to the settings
 * loaded by common components.
 *
 * To utilize this component within an application, configure the IoC loader
 * to use common Express components.
 *
 *     IoC.loader(require('bixby-express'));
 *
 * @param {Settings} settings
 * @param {Logger} logger
 * @return {Function}
 */
exports = module.exports = function(settings, logger) {
  
  return function httpServer(done) {
    var config = settings.get('server') || {};
    var address = config.address || '0.0.0.0';
    var port = config.port || 8080;
    
    
    if (cluster.isMaster && config.cluster) {
      var size = config.size || os.cpus().length;
      
      logger.info('Creating cluster with %d workers', size);
      
      for (var i = 0; i < size; ++i) {
        logger.info('Spawning worker process %d', (i + 1));
        cluster.fork();
      }
      
      cluster.on('fork', function(worker) {
        logger.info('Worker %s (%d) spawned', worker.id, worker.process.pid);
      });
      cluster.on('online', function(worker) {
        logger.info('Worker %s (%d) online', worker.id, worker.process.pid);
      });
      cluster.on('listening', function(worker, addr) {
        logger.info('Worker %s (%d) listening on %s:%d', worker.id, worker.process.pid, addr.address, addr.port);<commit_msg>Allow port to be set to 0 (system-assigned).<commit_after>/**
 * Module dependencies.
 */
var http = require('http')
  , https = require('https')
  , cluster = require('cluster')
  , os = require('os')
  , fs = require('fs');


/**
 * Component-ized boot phase that listens for HTTP requests.
 *
 * This component provides a boot phase that starts an HTTP or HTTPS server (or
 * cluster of such servers).  The server is configured according to the settings
 * loaded by common components.
 *
 * To utilize this component within an application, configure the IoC loader
 * to use common Express components.
 *
 *     IoC.loader(require('bixby-express'));
 *
 * @param {Settings} settings
 * @param {Logger} logger
 * @return {Function}
 */
exports = module.exports = function(settings, logger) {
  
  return function httpServer(done) {
    var config = settings.get('server') || {};
    var address = config.address || '0.0.0.0';
    var port = config.port !== undefined ? config.port : 8080;
    
    
    if (cluster.isMaster && config.cluster) {
      var size = config.size || os.cpus().length;
      
      logger.info('Creating cluster with %d workers', size);
      
      for (var i = 0; i < size; ++i) {
        logger.info('Spawning worker process %d', (i + 1));
        cluster.fork();
      }
      
      cluster.on('fork', function(worker) {
        logger.info('Worker %s (%d) spawned', worker.id, worker.process.pid);
      });
      cluster.on('online', function(worker) {
        logger.info('Worker %s (%d) online', worker.id, worker.process.pid);
      });
      cluster.on('listening', function(worker, addr) {
        logger.info('Worker %s (%d) listening on %s:%d', worker.id, worker.process.pid, addr.address, addr.port);
{'fraction_non_alphanumeric': 0.14985422740524781, 'fraction_numerical': 0.006122448979591836, 'mean_word_length': 2.9756662804171494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '774126', 'n_tokens_mistral': 1024, 'n_tokens_neox': 1002, 'n_words': 310}