How to use the os.cpus function in os

To help you get started, we’ve selected a few os examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular-cli / packages / angular / cli / models / analytics.ts View on Github external
function _buildUserAgentStringForOsx() {
  let v = osVersionMap.darwin[os.release()];

  if (!v) {
    // Remove 4 to tie Darwin version to OSX version, add other info.
    const x = parseFloat(os.release());
    if (x > 10) {
      v = `10_` + (x - 4).toString().replace('.', '_');
    }
  }

  const cpuModel = os.cpus()[0].model.match(/^[a-z]+/i);
  const cpu = cpuModel ? cpuModel[0] : os.cpus()[0].model;

  return `(Macintosh; ${cpu} Mac OS X ${v || os.release()})`;
}
github apache / incubator-superset / superset / assets / webpack.config.js View on Github external
// https://github.com/mapbox/mapbox-gl-js/issues/4359#issuecomment-288001933
    noParse: /(mapbox-gl)\.js$/,
    rules: [
      {
        test: /datatables\.net.*/,
        loader: 'imports-loader?define=>false',
      },
      {
        test: /\.tsx?$/,
        use: [
          { loader: 'cache-loader' },
          {
            loader: 'thread-loader',
            options: {
              // there should be 1 cpu for the fork-ts-checker-webpack-plugin
              workers: os.cpus().length - 1,
            },
          },
          {
            loader: 'ts-loader',
            options: {
              // transpile only in happyPack mode
              // type checking is done via fork-ts-checker-webpack-plugin
              happyPackMode: true,
            },
          },
        ],
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        include: APP_DIR,
github aikar / timings / node_modules / node-sass / node_modules / pangyp / lib / build.js View on Github external
if (win) {
      // Turn off the Microsoft logo on Windows
      argv.push('/nologo')
    }

    // Specify the build type, Release by default
    if (win) {
      var p = arch === 'x64' ? 'x64' : 'Win32'
      argv.push('/p:Configuration=' + buildType + ';Platform=' + p)
      if (jobs) {
        var j = parseInt(jobs, 10)
        if (!isNaN(j) && j > 0) {
          argv.push('/m:' + j)
        } else if (jobs.toUpperCase() === 'MAX') {
          argv.push('/m:' + require('os').cpus().length)
        }
      }
    } else {
      argv.push('BUILDTYPE=' + buildType)
      // Invoke the Makefile in the 'build' dir.
      argv.push('-C')
      argv.push('build')
      if (jobs) {
        var j = parseInt(jobs, 10)
        if (!isNaN(j) && j > 0) {
          argv.push('--jobs')
          argv.push(j)
        } else if (jobs.toUpperCase() === 'MAX') {
          argv.push('--jobs')
          argv.push(require('os').cpus().length)
        }
github Comcast / Speed-testJS / modules / domain.js View on Github external
function getCpu(){
    return os.cpus();
  }
  /**
github node-modules / zookeeper-cluster-client / example / cluster.js View on Github external
'use strict';

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
const zookeeper = require('..');

let latestData;
function getData(client, path) {
  client.getData(path, event => {
    console.log(event);
    getData(client, path);
  }, (err, data, meta) => {
    latestData = { data, meta };
    console.log(`${path} => ${data.toString()}, version: ${meta.version}`);
  });
}

if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);
github eclipse / orion.client / modules / orionode / lib / graceful-cluster / graceful-cluster.js View on Github external
var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

var GracefulCluster = module.exports;

/*

 Starts node.js cluster with graceful restart/shutdown.

 Params:

 - options.serverFunction        - required, function with worker logic.
 - options.log                   - function, custom log function, console.log used by default.
 - options.shutdownTimeout       - ms, force worker shutdown on SIGTERM timeout.
 - options.disableGraceful       - disable graceful shutdown for faster debug.
 - options.restartOnMemory       - bytes, restart worker on memory usage.
 - options.restartOnTimeout      - ms, restart worker by timer.
 - options.workersCount          - workers count, if not specified `os.cpus().length` will be used.
github Samaritan89 / lesson / 09 Process / cp / master1.js View on Github external
"use strict";

const cpus = require('os').cpus();
const fork = require('child_process').fork;

for(let i = 0, len = cpus.length; i < len; i++){
	fork('./worker1.js');
}
github lazojs / lazo / run.js View on Github external
function getStartEnvOptions() {
    var options = {};

    for (var k in args) {
        switch (k) {
            case 'daemon':
            case 'robust':
                options[k] = args[k] === true ? '1' : '0';
                break;
            case 'cluster':
                options[k] = args[k] ? args[k] : os.cpus().length;
                break;
            case 'port':
                options[k] = args[k];
                break;
        }
    }

    return options;
}
github nightwatchjs / nightwatch / lib / runner / concurrency / concurrency.js View on Github external
getTestWorkersCount() {
    let workers = 1;
    if (this.settings.test_workers === true || this.settings.test_workers.workers === 'auto') {
      workers = require('os').cpus().length;
    } else if ('number' == typeof this.settings.test_workers.workers) {
      workers = this.settings.test_workers.workers;
    }

    return workers;
  }
github project-yuigahama / Yuigahama / src / lib / error / Reporter.js View on Github external
if (!(error instanceof Error)) return
    if (!(client instanceof KlasaClient)) return
    return [
      '=== Yuigahama Error Report ===',
      `Date                                :: ${timestamp.display()}`,
      '',
      '=== Error ===',
      `${error.stack}`,
      '',
      '=== Bot ===',
      `Average ping of all WebSocketShards :: ${Math.round(client.ws.ping)}ms`,
      `Ready at                            :: ${client.ready ? timestamp.display(client.readyTimestamp) : 'None'}`,
      '',
      '=== System ===',
      `OS                                  :: ${getPlatform()}`,
      `CPU                                 :: ${os.cpus()[0].model}`,
      `Memory                              :: ${Math.round(process.memoryUsage().rss / 1024 / 1024 * 100) / 100}/${(os.totalmem() / 1024 / 1024).toFixed(2)}MB`,
      '',
      '=== Versions ===',
      `Yuigahama                           :: v${YuigahamaVersion}`,
      `Klasa                               :: v${KlasaVersion}`,
      `Discord.js                          :: v${discordVersion}`,
      `Node.js                             :: v${process.versions.node}`
    ].join('\n')
  }