Chaining .add()
s creates a sequential Flow. For parallelism, use the needs
parameter:
from jina import Flow
Flow().add(name='p1', needs='gateway') \
.add(name='p2', needs='gateway') \
.add(name='p3', needs='gateway') \
.needs(['p1','p2', 'p3'], name='r1')
p1
, p2
, p3
now subscribe to Gateway
and conduct their work in parallel. The last .needs()
blocks all Pods until they finish their work. Note: parallelism can also be performed inside a Pod using parallel
:
Flow().add(name='p1', needs='gateway') \
.add(name='p2', needs='gateway') \
.add(name='p3', parallel=3) \
.needs(['p1','p3'], name='r1')