Skip to content

Parallelize graph verifications #183

Description

@nk-ag

Summary

Parallelize graph verification to reduce end-to-end validation time in verify_graph.

Target

Run the following in parallel since they are independent:

  • verify_nodes_names(graph_template.nodes)
  • verify_nodes_namespace(graph_template.nodes, graph_template.namespace)
  • verify_node_exists(graph_template.nodes, database_nodes)
  • verify_node_identifiers(graph_template.nodes)
  • verify_secrets(graph_template, database_nodes)

Run verify_topology(graph_template.nodes) after the above complete.

Plan

  • Refactor each verifier to return list[str] of errors instead of mutating a shared errors list.
  • Aggregate results with asyncio.gather, then call topology verification only if no blocking errors.
  • Keep DB calls async. If needed, bound concurrency with a semaphore for lookups.

Sketch

importasyncioasyncdefverify_graph(graph_template, database_nodes):
tasks= [
verify_nodes_names(graph_template.nodes),
verify_nodes_namespace(graph_template.nodes, graph_template.namespace),
verify_node_exists(graph_template.nodes, database_nodes),
verify_node_identifiers(graph_template.nodes),
verify_secrets(graph_template, database_nodes),
]
results=awaitasyncio.gather(*tasks, return_exceptions=True)
errors= []
forrinresults:
ifisinstance(r, Exception):
errors.append(f"Verifier failed: {r}")
else:
errors.extend(r)
dependency_graph=Noneifnoterrors:
dependency_graph=awaitverify_topology(graph_template.nodes)
returndependency_graph, errors

Tests

  • Unit tests: each verifier returns errors deterministically, no shared state.
  • Integration: simulate slow I/O in one verifier and confirm total time is close to the max of individual times, not the sum.
  • Failure path: any verifier raises or returns errors, topology is skipped.

Acceptance criteria

  • Verifiers run concurrently and overall verification time decreases.
  • No shared mutable errors across tasks.
  • Topology runs only after basic checks pass.
  • CI green with new tests and type hints updated.

Metadata

Metadata

Assignees

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions