You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KV-store chords restore the whole group on every header task (O(N²)) #11045
For backends that count chords with incr (memcached, DynamoDB, ...), BaseKeyValueStoreBackend.on_chord_part_return calls GroupResult.restore(gid) on every header task before incrementing:
With the default result_cache_max=-1 nothing is cached, so each part fetches and decodes the whole group (N results). That is O(N²) for a chord of N tasks, e.g. ~10k reads of the full group blob for a 10k header.
The code expects request.chord["chord_size"] to avoid using len(deps), but nothing sets it since #6576 removed body.chord_size = ... from canvas. GCS (gcs.py) relies on the same key.
Fix idea: set chord_size on the body in _chord.run (header leaf count, as _descend already computes), then in on_chord_part_returnincr first and only restore the group when the counter reaches the size.
Found by code reading (AI-assisted), not measured yet. Happy to send a PR with tests if this is confirmed.
This reproduces on main (9c2f238) and on 5.6.2 with the cache+memory:// backend: GroupResult.restore() runs once per header task.
Header tasks in the chord
GroupResult.restore() calls
5
5
10
10
20
20
40
40
Each call loads the whole group, so the work grows with the square of the header size. By blame, chord_size stopped being set on the body in #6576, first released in 5.1.0. I did not run a release before that.
I tested the fix from the description on main (22be744): _chord.run sets body['chord_size'] = _descend(header) (the same count Redis uses), and on_chord_part_return calls incr first and restores the group only when the counter reaches that size. With cache+memory:// and a real worker, GroupResult.restore() now runs once per chord instead of once per header task (5/10/20/40 → 1). Headers built from a generator keep the old fallback, so they stay lazy (#3021).
While testing I found a related bug on main: chord([chain(a.s(), group(b.si(), c.si())), d.s()], body) hangs with this backend. len(deps) is 2 but 3 parts report, so the chord never completes; with the size from _descend it completes.
I have a branch with unit tests. @auvipy, could you confirm this is wanted? If so, and the author hasn't already started, I'll open a PR.
Activity
ChristianMurphy commentedon Nov 16, 2026
This reproduces on main (
9c2f238) and on 5.6.2 with thecache+memory://backend:GroupResult.restore()runs once per header task.GroupResult.restore()callsEach call loads the whole group, so the work grows with the square of the header size. By blame,
chord_sizestopped being set on the body in #6576, first released in 5.1.0. I did not run a release before that.binnguyenx commentedon Nov 27, 2026
I tested the fix from the description on
main(22be744):_chord.runsetsbody['chord_size'] = _descend(header)(the same count Redis uses), andon_chord_part_returncallsincrfirst and restores the group only when the counter reaches that size. Withcache+memory://and a real worker,GroupResult.restore()now runs once per chord instead of once per header task (5/10/20/40 → 1). Headers built from a generator keep the old fallback, so they stay lazy (#3021).While testing I found a related bug on
main:chord([chain(a.s(), group(b.si(), c.si())), d.s()], body)hangs with this backend.len(deps)is 2 but 3 parts report, so the chord never completes; with the size from_descendit completes.I have a branch with unit tests. @auvipy, could you confirm this is wanted? If so, and the author hasn't already started, I'll open a PR.
auvipy commentedon Nov 28, 2026
@binnguyenx ok come with a proper fix