Remote Executor

JinaD enables deploying Executors on remote machines. We can pass the remote info using hostand port_jinad arguments in the Flow syntax. Here are a few examples of using remote Executors.

Executor defined in YAML

from jina import Flow

f = Flow().add(uses='executor.yml',
               py_modules=['executor.py'])
from jina import Flow

f = Flow().add(uses='executor.yml',
               host='1.2.3.4',
               port_jinad=8000,
               py_modules=['executor.py'])

Executor from Hub

from jina import Flow

f = Flow().add(uses='jinahub+docker://AdvancedExecutor')
from jina import Flow

f = Flow().add(uses='jinahub+docker://AdvancedExecutor',
               host='1.2.3.4',
               port_jinad=8000)

Executors on different hosts

from jina import Flow

f = (Flow()
    .add(name=’encoder’,
         uses='encoder.yml',
         py_modules=['encoder.py'])
    .add(name=’indexer’,
         uses='indexer.yml',
         py_modules=[‘indexer.py'])
    )
f = (Flow()
    .add(name=’encoder’,
         uses='encoder.yml',
         host='1.2.3.4'
         port_jinad=8000,
         py_modules=['encoder.py'])
    .add(name=’indexer’,
         uses='indexer.yml',
         host='2.3.4.5',
         port_jinad=8000,
         py_modules=[‘indexer.py'])
    )

Executor using class

from jina import Flow, Executor, requests

class MyAwesomeExecutor(Executor):
    @requests
    def foo(*args, **kwargs):
        ...

f = Flow().add(uses=MyAwesomeExecutor)
from jina import Flow, Executor, requests

class MyAwesomeExecutor(Executor):
    @requests
    def foo(*args, **kwargs):
        ...

f = Flow().add(uses=MyAwesomeExecutor,
               host='1.2.3.4',
               port_jinad=8000,
               py_modules=['path/to/this/file.py'])

Executor using class + pip dependency

from jina import Flow, Executor, requests

class TFExecutor(Executor):
    @requests
    def foo(*args, **kwargs):
        import tensorflow
        ...

f = Flow().add(uses=TFExecutor)
# requirements.txt
tensorflow==2.4.0
from jina import Flow, Executor, requests

class TFExecutor(Executor):
    @requests
    def foo(*args, **kwargs):
        import tensorflow
        ...

f = Flow().add(uses=TFExecutor,
               host='1.2.3.4',
               port_jinad=8000,
               py_modules=['path/to/this/file.py'],
               upload_files=['requirements.txt'])

Using GPU with any remote Executor

f = Flow().add(uses=TFExecutor,
               host='1.2.3.4',
               port_jinad=8000,
               py_modules=['path/to/this/file.py'],
               upload_files=['requirements.txt'])
f = Flow().add(uses=TFExecutor,
               host='1.2.3.4',
               port_jinad=8000,
               py_modules=['path/to/this/file.py'],
               upload_files=['requirements.txt'],
               gpus='all')

Caution

Directory structure for Executors is not supported in JinaD yet.