-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pylint -j0 always uses 1 core on real hardware in Linux #7338
Comments
@dsilakov I must say I'm no expert in containers and CPU's so I'll likely need some help fixing this. Based on discussion in https://bugs.python.org/issue36054 and the implementation of CPU counting in Am I correct in thinking that we incorrectly determine whether |
To be more precise - in JVM, the magic you are referencing to happens inside the OSContainer class and JVM seems to have some trickier logic when detecting if it is running "containerized" (under cgroup control) or not. Having /sys/fs/cgroup/cpu/cpu.shares and other cpu.shares for particular processes on the host system is completely legit - for example, systemd uses them to limit CPU resources. However I don't see a generic way to transform these "shares" to real cores since this depends on how many other processes do you have. Maybe division by 1024 indeed works inside AWS, but this still looks like some kind of heuristic. A good explanation is provided for example in https://www.batey.info/cgroup-cpu-shares-for-docker.html:
|
Heh, after a closer look, JVM also contains a set of hacks for treating cpu.shares equal to 1024: https://github.com/openjdk/jdk/blob/master/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp#L278 Honestly I don't know what should be a proper fix for pylint here. For our scenarios, I've just commented out "elif os.path.isfile('/sys/fs/cgroup/cpu/cpu.shares')" part. In our K8s cluster and dockers we do see /sys/fs/cgroup/cpu/cpu.cfs_quota_us so the code still works fine inside the containers. But I can't check AWS for which the problematic elif was intended for. |
Yeah, I'm not an user of AWS myself but I'm wondering if there is some other way we can use to detect if we are in an AWS environment instead of what we currently use in the |
We had a duplicate opened in #9537 and the op said pytest does things correctly. So here's how pytest-xdist does it: |
That solution is still not perfect, if you run it inside docker container than it won't take container limitations into account. E.g., inside a container launched via |
Bug description
-j0 should automatically detect number of processors available. However, after the changes that introduce _cpu_count() function for calculation available resources in clouds, this works incorrectly on real hardware.
A potential problem lies here: https://github.com/PyCQA/pylint/blob/main/pylint/lint/run.py#L59
If we reach this code (we don't have cpu.cfs_quota_us set) then we always divide /sys/fs/cgroup/cpu/cpu.shares by 1024. Maybe this is correct for AWS, but e.g. in ubuntu 20.04 cpu.shares is set to 1024 by default. So it doesn't matter how many cpu cores do you have, pylint -j0 will always use only one of them.
The whole idea of using cpu.shares in such a way looks strange, since it just declares an allowed "share" of CPU resources for the particular process.
Configuration
Command used
Pylint output
Expected behavior
$ time pylint -j0 pylint/*
8 sec
$ time pylint -j1 pylint/*
30 sec
$ time pylint -j12 pylint/*
8 sec
Pylint version
OS / Environment
Ubuntu 20.04 x86_64
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: