Skip to content

parallel: Var counters for forked workers - #70

Open
Niols wants to merge 2 commits into
ahrefs:masterfrom
Niols:parallel-fork-counters
Open

Niols wants to merge 2 commits into
ahrefs:masterfrom
Niols:parallel-fork-counters

Conversation

@Niols

@Niols Niols commented Sep 27, 2026

Copy link
Copy Markdown

Add a parallel.forks Var family to gain observability on workers forked by Parallel.run_forks. Counted per event:

  • spawned — worker was forked
  • exited — terminated normally, on its own or on SIGTERM from the parent
  • killed — worker did not stop in time and was SIGKILL'ed
  • vanished — crashed, or exited with non-zero status

We already have startup and termination event sent by the processes themselves, which I believe duplicates the work of spawned and exited, so let me know if I should clean those up. Workers that get killed or that vanished presumably don't get to write this termination event.

I decided to imitate httpev.forks in that the counters are process-wide and several run_forks in the same process cannot be told apart. I also haven't allowed passing a ~attrs or something to customize the vars in each call. Let me know if you would want something different.

I wasn't sure on whether to reset the counters in forked children via Nix.register_on_fork so I've done it in a separate commit, which I can drop easily.

See https://ahrefs.slack.com/archives/C01NT4U32JD/p1790263319380559

Nicolas Jeannerod and others added 2 commits September 27, 2026 13:38
Count spawned/exited/vanished/killed workers in the "parallel.forks"
family, in both the pooled and the supervised implementations.
Counters are process-wide as in Httpev, several run_forks calls are
not told apart.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A child inherits a snapshot of the Var registry, so a worker reporting
its own stats would emit the parent's fork counts frozen at fork time.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@rr0gi rr0gi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think better add counters to do_stop, this way can see when workers are exiting slowly / not uniformly. You decide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants