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

Tests not parallelized efficienctly by pytest #5755

Closed
JukkaL opened this issue Oct 9, 2018 · 3 comments
Closed

Tests not parallelized efficienctly by pytest #5755

JukkaL opened this issue Oct 9, 2018 · 3 comments
Labels
priority-0-high topic-developer Issues relevant to mypy developers

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 9, 2018

When I run pytest mypy, towards the end of a test run only 1 or 2 python processes are running and test progress is very slow -- each process is using much less than 100% of a CPU. This happens even though I requested 8 parallel processes. Initially I see 8 processes doing work, but something causes a slowdown towards the end of a test run.

This doesn't look like a recent regression, but I think that things have gotten worse in the last few months or so.

Some data (Linux, Intel 4-core/8-thread CPU):

  • When I check out e378601 from May 2018, tests finish in 66s (6024 tests).
  • When I check out 1606f0f from Oct 2018, tests finish in 133s (6671 tests).

This seems to happen both on Linux and macOS.

Updating to the latest pytest doesn't help.

It would be great if somebody could try to reproduce the issue.

@ethanhs
Copy link
Collaborator

ethanhs commented Oct 9, 2018

Yes, I have seen this too. The problem seems to get worse the more cores you throw at it. I went ahead and checked out e378601 and it only takes 57 seconds on my 16 core machine, while master takes 240s.

It seems this is a known issue with pytest-xdist:
pytest-dev/pytest-xdist#40
pytest-dev/pytest-xdist#18

@ilevkivskyi
Copy link
Member

I see this all the time for last few months (and mentioned it internally a while ago). I tried to play one day with different scheduling modes (xdist has some), but I was never able to get efficient load scheduling.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 10, 2018

I'm not sure if the reported pytest-xdist issues are relevant. It looks like too many slow tests are scheduled for certain processes, and other processes are starved.

I have a workaround that seems to improve the runtime to about 81s on master (on the Linux system I mentioned above). It splits the test run into two pytest invocations. I don't love the approach but it's probably worth the performance increase. I'll prepare a PR once I've verified that it works generally.

@JukkaL JukkaL added priority-0-high topic-developer Issues relevant to mypy developers labels Oct 10, 2018
JukkaL added a commit that referenced this issue Oct 11, 2018
This can speed up test runtimes by 15% to 50%. Also this makes it easier
to rerun only part of the test suite.

Fixes #5755.

The same issue may also affect travis and appveyor builds, and this doesn't
address them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-0-high topic-developer Issues relevant to mypy developers
Projects
None yet
Development

No branches or pull requests

3 participants