Skip to content

Parallelize graph verifications #183

@nk-ag

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

import asyncio

async def verify_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 = await asyncio.gather(*tasks, return_exceptions=True)

    errors = []
    for r in results:
        if isinstance(r, Exception):
            errors.append(f"Verifier failed: {r}")
        else:
            errors.extend(r)

    dependency_graph = None
    if not errors:
        dependency_graph = await verify_topology(graph_template.nodes)

    return dependency_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