From b131e4194d298bd94f2267648d2f6fbd1a7801c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kohlsdorf?= Date: Wed, 24 Feb 2021 16:39:58 -0300 Subject: [PATCH] perf(scheduler): sort scopes by number of tests to start with biggest scope first --- changelog/632.feature.rst | 1 + src/xdist/scheduler/loadscope.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog/632.feature.rst diff --git a/changelog/632.feature.rst b/changelog/632.feature.rst new file mode 100644 index 00000000..0e3b6e4d --- /dev/null +++ b/changelog/632.feature.rst @@ -0,0 +1 @@ +LoadScope scheduler: Sort scopes by number of tests to assign biggest scopes first. diff --git a/src/xdist/scheduler/loadscope.py b/src/xdist/scheduler/loadscope.py index 31dbe26c..59c262d5 100644 --- a/src/xdist/scheduler/loadscope.py +++ b/src/xdist/scheduler/loadscope.py @@ -349,11 +349,18 @@ def schedule(self): return # Determine chunks of work (scopes) + unsorted_workqueue = OrderedDict() for nodeid in self.collection: scope = self._split_scope(nodeid) - work_unit = self.workqueue.setdefault(scope, default=OrderedDict()) + work_unit = unsorted_workqueue.setdefault(scope, default=OrderedDict()) work_unit[nodeid] = False + # Insert tests scopes into work queue ordered by number of tests + for scope, nodeids in sorted( + unsorted_workqueue.items(), key=lambda item: -len(item[1]) + ): + self.workqueue[scope] = nodeids + # Avoid having more workers than work extra_nodes = len(self.nodes) - len(self.workqueue)