Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always assume at least one cpu #6484

Merged
merged 1 commit into from
Jul 16, 2018
Merged

always assume at least one cpu #6484

merged 1 commit into from
Jul 16, 2018

Conversation

jquense
Copy link
Contributor

@jquense jquense commented Jul 16, 2018

alpine doesn't come with lscpu so the cpu check fails, reporting 0, meaning no pages are written out

@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit 7c70937

https://deploy-preview-6484--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit 7c70937

https://deploy-preview-6484--gatsbygram.netlify.com

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pieh pieh merged commit 24e505f into master Jul 16, 2018
@pieh
Copy link
Contributor

pieh commented Jul 16, 2018

I wonder if we should provide way to set this up in config and add warning that Gatsby can't determine core count

@KyleAMathews KyleAMathews deleted the jquense-patch-1 branch July 16, 2018 18:51
@KyleAMathews
Copy link
Contributor

Yeah, maybe have a way to set the worker count or something via an env variable.

I am surprised though that it doesn't work on Alpine Linux (what @jquense reported on Discord)

@jquense
Copy link
Contributor Author

jquense commented Jul 16, 2018

I was gonna check the npm package source, but its not on github that I can find...I'm sure there is a more robust way to handle this but i have no idea...

@KyleAMathews
Copy link
Contributor

This is the code in node_modules

'use strict'

const os = require('os')
const childProcess = require('child_process')

function exec (command) {
  const output = childProcess.execSync(command, {encoding: 'utf8'})
  return output
}

let amount
const platform = os.platform()

if (platform === 'linux') {
  const output = exec('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l')
  amount = parseInt(output.trim(), 10)
} else if (platform === 'darwin') {
  const output = exec('sysctl -n hw.physicalcpu_max')
  amount = parseInt(output.trim(), 10)
} else if (platform === 'windows') {
  const output = exec('WMIC CPU Get NumberOfCores')
  amount = output.split(os.EOL)
    .map(function parse (line) { return parseInt(line) })
    .filter(function numbers (value) { return !isNaN(value) })
    .reduce(function add (sum, number) { return sum + number }, 0)
} else {
  const cores = os.cpus().filter(function (cpu, index) {
    const hasHyperthreading = cpu.model.includes('Intel')
    const isOdd = index % 2 === 1
    return !hasHyperthreading || isOdd
  })
  amount = cores.length
}

module.exports = amount
@jquense
Copy link
Contributor Author

jquense commented Jul 16, 2018

o maybe it should fallback to that last branch?

@KyleAMathews
Copy link
Contributor

Yeah, if amount is 0 or undefined or whatever, then it should fallback on the last option.

@KyleAMathews
Copy link
Contributor

Weird the package isn't on github.

@millette
Copy link
Contributor

millette commented Jul 18, 2018

https://gitlab.com/sebdeckers/physical-cpu-count/

I was just bit by that, testing the new https://zeit.co/blog/dockerfile-static UPDATE: fixed URL

@millette
Copy link
Contributor

My workaround was to add this to my Alpine Dockerfile:

RUN apk add --no-cache util-linux
@KyleAMathews
Copy link
Contributor

@millette — are you on the latest Gatsby beta? @jquense did PR a fix for this yesterday.

@millette
Copy link
Contributor

"version": "2.0.0-beta.38", but I see beta.44 was released. Usually, yarn outdated tells me.

I will remove my workaround and give the new version a go.

@millette
Copy link
Contributor

Indeed, that worked flawlessly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants