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

Virtualized or containerized environments might not report number of CPUs correctly #9

Closed
thedrow opened this issue Nov 9, 2015 · 8 comments

Comments

@thedrow
Copy link
Contributor

thedrow commented Nov 9, 2015

This problem is mainly present itself in CI environments like the ones Travis provides.
When you use -n auto xdist will create more workers than what's available for the container/VM since that is what's written in the /proc/ filesystem which multiprocessing.cpu_count() reads the number of CPUs from.
A possible solution would be to use psutil which might be able to read the /proc/ filesystem more correctly but I'm not 100% sure about it.

As a workaround I'd like to suggest adding:

if os.environ.get('TRAVIS') == 'true' and n == 'auto':
  cpu_count = 2

to the code to prevent spawning too many processes and slowing down test runs.
A better workaround would be to provide a hook to allow to reinterpret what auto means and return a different number.

@thedrow
Copy link
Contributor Author

thedrow commented Nov 9, 2015

Based on the tests in #10 it seems that os.cpu_count() doesn't respond with the correct answer so psutil won't either since it implemented the same way as os.cpu_count().

@RonnyPfannschmidt
Copy link
Member

i presume the only way to do this correct is to get travis use the lxc-proc filesystem for containers (which provides a corrected view of proc)

@thedrow
Copy link
Contributor Author

thedrow commented Nov 9, 2015

But not all of their environments use lxc.

@RonnyPfannschmidt
Copy link
Member

does it also report it wrong on top of a kvm/osx?

@thedrow
Copy link
Contributor Author

thedrow commented Nov 9, 2015

On KVM yes, you get the same results as with LXC. No idea what about OSX.

@thedrow
Copy link
Contributor Author

thedrow commented Nov 9, 2015

I think that providing a hook will workfor now. We can document that under Travis your conftest.py should look like:

def pytest__xdist_auto_workers(cpu_count):
  if os.environ.get('TRAVIS') == 'true':
    return 2
  return cpu_count

Not sure about the hook name though.

@nicoddemus
Copy link
Member

pytest-vw contains a pretty good list of known CI services. I think it would be nice for xdist to work out of the box with those.

nicoulaj added a commit to nicoulaj/rainbow that referenced this issue Mar 19, 2017
Signed-off-by: Julien Nicoulaud <julien.nicoulaud@gmail.com>
nicoulaj added a commit to nicoulaj/rainbow that referenced this issue Mar 19, 2017
…/pytest-xdist#9

Signed-off-by: Julien Nicoulaud <julien.nicoulaud@gmail.com>

# Veuillez saisir le message de validation pour vos modifications. Les lignes
# commençant par '#' seront conservées ; vous pouvez les supprimer vous-même
# si vous le souhaitez. Un message vide abandonne la validation.
#
# Date :       Sun Mar 19 13:49:16 2017 +0100
#
# Sur la branche master
# Votre branche et 'origin/master' ont divergé,
# et ont 1 et 1 commits différents chacune respectivement.
#   (utilisez "git pull" pour fusionner la branche distante dans la vôtre)
#
# Modifications qui seront validées :
#	modifié :         tox.ini
#
nicoulaj added a commit to nicoulaj/rainbow that referenced this issue Mar 19, 2017
…/pytest-xdist#9

Signed-off-by: Julien Nicoulaud <julien.nicoulaud@gmail.com>
@nicoddemus
Copy link
Member

Fixed by #309.

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

No branches or pull requests

3 participants