This commit is contained in:
Eugene Yurtsev
2025-03-18 21:53:56 -04:00
parent 24f7d7c439
commit b440b14fa7
2 changed files with 47 additions and 1 deletions
+46
View File
@@ -29,6 +29,21 @@ async def arun(graph: Pregel, input: dict):
)
async def arun_first_event_latency(graph: Pregel, input: dict) -> None:
"""Latency for the first event.
Run the graph until the first event is processed and then stop.
"""
async for _ in graph.astream(
input,
{
"configurable": {"thread_id": str(uuid4())},
"recursion_limit": 1000000000,
},
):
break
def run(graph: Pregel, input: dict):
len(
[
@@ -44,6 +59,21 @@ def run(graph: Pregel, input: dict):
)
def run_first_event_latency(graph: Pregel, input: dict) -> None:
"""Latency for the first event.
Run the graph until the first event is processed and then stop.
"""
for _ in graph.stream(
input,
{
"configurable": {"thread_id": str(uuid4())},
"recursion_limit": 1000000000,
},
):
break
benchmarks = (
(
"fanout_to_subgraph_10x",
@@ -330,7 +360,23 @@ benchmarks = (
r = Runner()
# Full graph run time
for name, agraph, graph, input in benchmarks:
r.bench_async_func(name, arun, agraph, input, loop_factory=new_event_loop)
if graph is not None:
r.bench_func(name + "_sync", run, graph, input)
# First event latency
for name, agraph, graph, input in benchmarks:
r.bench_async_func(
name + "_first_event_latency",
arun_first_event_latency,
agraph,
input,
loop_factory=new_event_loop,
)
if graph is not None:
r.bench_func(
name + "_first_event_latency_sync", run_first_event_latency, graph, input
)
+1 -1
View File
@@ -4,7 +4,7 @@ from langgraph.graph import MessagesState, StateGraph
from langgraph.utils.runnable import RunnableCallable
def create_sequential(number_nodes) -> StateGraph:
def create_sequential(number_nodes: int) -> StateGraph:
"""Create a sequential no-op graph consisting of a few hundred nodes."""
builder = StateGraph(MessagesState)