Skip to content

parallel: Var counters for forked workers - #70

Open
Niols wants to merge 1 commit into
ahrefs:masterfrom
Niols:parallel-fork-counters
Open

Niols wants to merge 1 commit 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
  • succeeded — exited with return code 0
  • failed — exited with non-zero return code
  • signaled — stopped from a signal, whether it is a SIGINT or SIGTERM coming from the parent, or coming from anywhere else, or stuff like SIGABRT, etc. I don't think we should do any special treatment of signals at the level of Devkit because their semantics depends a lot on the final program and what workers do with signals.
  • vanished — crashed, disappeared, etc.
  • force_killed — worker did not stop in time and was SIGKILL'ed

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 force_killed, that vanished, or that died because signaled 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.

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

@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

Count workers in the "parallel.forks" Var family, per event: spawned,
succeeded (exit status 0), failed (non-zero exit status), signaled
(killed by a signal), vanished (lost without a status, e.g. mid-task
in the pool) and force_killed (SIGKILLed for not stopping in time).

Exits are counted as workers are reaped, so slow or uneven stops show
up while they happen. Counters are process-wide as in Httpev: several
run_forks calls are not told apart. They are reset in forked children,
which would otherwise report the parent's counts frozen at fork time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Niols
Niols force-pushed the parallel-fork-counters branch from a3da706 to 240a85f Compare October 14, 2026 11:51
@Niols

Niols commented Oct 14, 2026

Copy link
Copy Markdown
Author

Updated the PR with most of the work happening in reap, which do_stop calls. Changed the semantics of the counters to make it more down to Earth (it is then up to the dashboard consumer, which knows the actual program's semantics, to make sense of them). Let me know if you would see other changes.

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