Open superstar54 opened 3 months ago
Attention: Patch coverage is 16.40431%
with 1009 lines
in your changes missing coverage. Please review.
Project coverage is 67.30%. Comparing base (
5937b88
) to head (8299fe5
). Report is 60 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Background
When running a workflow (such as a WorkChain or WorkGraph), each workflow is associated with a corresponding process. This process launches and waits for the child processes (e.g., CalcJob processes). In nested workflows like the
PwBandsWorkChain
, you may encounter multiple Workflow processes in a waiting state, with only one CalcJob process actively running. These waiting Workflow processes can be seen as inefficient resource usage.In a
WorkChain
, the workflow logic is encapsulated within the newWorkChain
class, making it challenging to eliminate these waiting processes at the moment. However, in aWorkGraph
, the logic is more explicitly defined, and it has strict rules on who can execute this logic.Besides, it's not good to run the task process and workgraph process in the same runner.
Proposal
To address this, I proposed a Scheduler for the
WorkGraph
in this PR. The Scheduler handles the following:WorkGraph
process only in the database without actually running the process by a daemon worker.CalcJob
, it launches it to the daemon worker as usual. The key difference here is that the Scheduler uses theWorkGraph
's PK as the parent PID, thereby maintaining correct provenance.Let's compare the process count for the
PwBands
case. Suppose we launch 100PwBands
WorkGraphs:The benefit is clear: the new approach significantly reduces the number of active processes.
Moreover, the Scheduler runs in a separate daemon that does not listen to process launching tasks, thereby eliminating the possibility of deadlocks that could occur with the old approach.This is also related to these issues:
Workflow process may spawn child processes which they wait on, however if there are no more slots left this child will never run and the parent will wait indefinitely whilst blocking a slot. More details in https://github.com/aiidateam/aiida-core/issues/1397.
User wants to control the maximum running job on a computer.
Note: this scheduler is designed for WorkGraph only. For WorkChain, this will not work.
Usage
https://aiida-workgraph--275.org.readthedocs.build/en/275/howto/scheduler.html
Scheduler
Add a daemon runner for scheduler:
scheduler_queue
, and the prefetch_count is set to 1. Thus, each runner can only launch one Scheduler process.workgraph_queue
to launch WorkGraphKeep provenance
parent_pid
, so that there is a link between the workgraph and the task's process.parent_pid
, and launch the workgraph inside the scheduler.Use one scheduler process or scale the number of processes when needed.
While a single scheduler suffices for most use cases, scaling up the number of schedulers may be beneficial when significantly increasing the number of task workers (created by
verdi daemon start
). A general rule is to maintain a ratio of less than 5 workers per scheduler.Circus
Similar to the
worker
daemon, we use circus to manage thescheduler
daemon.command
Todo
Scheduler
process instead of launching a new one.scheduler_queue
in rmq is increased because the runner does not ack. For example, when the runner stop, the scheduler process is still running, so the runner does not ack back to rmq. When the runner restarts, it will processed the first msg in the queue, but I also send a new msg to the queue to continue the scheduler. This is bug, we don't need send the msg to continue, because, it is already there.checkpoint
how do we save the checkpoint? instead of saving all data every time, it would be great if we only update the context related with the workgraph.
solution 1
save the ctx data for a workgraph to the extras of that workgraph.
submit calcfuntion
I tested, one can submit a calcfunction if it is inside a package, thus the daemon can load it back using
importlib.import_module
. For calcfunction defined on-the-fly, it will raise an error.Other features after this PR
workgraph_queue
, or run directly in the same scheduler?workgraph_queue
will make the schedulers more balanced