{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true, "pycharm": { "name": "#%% md\n" } }, "source": [ "## Inter & Intra Parallelism\n", "\n", "Chaining `.add()`s creates a sequential Flow. For parallelism, use the `needs` parameter:" ] }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "from jina import Flow\n", "\n", "Flow().add(name='p1', needs='gateway') \\\n", " .add(name='p2', needs='gateway') \\\n", " .add(name='p3', needs='gateway') \\\n", " .needs(['p1','p2', 'p3'], name='r1')" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "`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`:" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "Flow().add(name='p1', needs='gateway') \\\n", " .add(name='p2', needs='gateway') \\\n", " .add(name='p3', parallel=3) \\\n", " .needs(['p1','p3'], name='r1')" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } } ], "metadata": { "kernelspec": { "display_name": "${KERNEL_SPEC_DISPLAY_NAME}", "language": "${KERNEL_SPEC_LANGUAGE}", "name": "${KERNEL_SPEC_NAME}" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" }, "pycharm": { "stem_cell": { "cell_type": "raw", "source": [], "metadata": { "collapsed": false } } } }, "nbformat": 4, "nbformat_minor": 0 }