The teardown half of the pre-alpha11 audit's deferred performance work. PERF-3 (the pending-actions scan) split out to #3610809; this issue is now just the teardown batching (PERF-4).

Problem

cancelInstance() and failInstance() mark the instance terminal, then call cancelLiveTokens() to cancel each live token through cancel(). Two things there read the instance table once per token: cancel()'s completion and stall rechecks (checkCompletion() and recoverStalledInstance(), each loading the instance uncached only to early-return, since the instance is already terminal), and cancelChildInstances(), which looks up a token's running subprocess children one token at a time. So tearing an instance with many live branches down issues several instance-table reads per branch.

Fix

  • Extract cancel()'s token cascade into a helper. cancel() keeps the completion and stall recheck, since its other callers (a superseded branch, a discriminator join, a timer cancel) run on a still-running instance and need it, but the bulk teardown skips it: every caller of cancelLiveTokens() has already flipped the instance terminal, so the rechecks could only early-return.
  • Batch the subprocess-child teardown: cancelLiveTokens() collects the ids of the tokens it cancelled and loads their running children in one parent-token IN query, rather than a lookup per token.
  • cancelTimers() loads its pending timer tokens with one loadMultiple() instead of a query per id.

A kernel test tears down a two-branch and a five-branch instance and asserts the instance-table read count is identical, so teardown is O(1) in the branch count, not O(n).

Pre-1.0 and no schema change, so nothing to apply on the live site.

Issue fork orchestra-3610755

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Title: Pending-actions and teardown performance: page the actions scan and batch instance teardown » Batch instance teardown so its instance reads do not scale with the token count
Issue summary: View changes

mably’s picture

Status: Active » Needs review
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mably committed 008333c2 on 1.x
    task: #3610755 Batch instance teardown so its instance reads do not...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.