Remote Executors
JinaD enables deploying Executors on remote machines. We can pass the remote host details using host
and port_jinad
arguments in the Flow syntax. Here are a few examples of using remote Executors.
Executors from Hub
Local (jinahub+docker)
from jina import Flow
f = Flow().add(uses='jinahub+docker://AdvancedExecutor')
Remote (jinahub+docker)
from jina import Flow
f = Flow().add(uses='jinahub+docker://AdvancedExecutor',
host='1.2.3.4',
port_jinad=8000)
Local (jinahub)
from jina import Flow
f = Flow().add(uses='jinahub://AdvancedExecutor',
install_requirements=True)
Remote (jinahub)
from jina import Flow
f = Flow().add(uses='jinahub://AdvancedExecutor',
install_requirements=True,
host='1.2.3.4',
port_jinad=8000)
Executors on different hosts
Local
from jina import Flow
f = (
Flow()
.add(name='encoder',
uses='jinahub+docker://AdvancedExecutor1')
.add(name='indexer',
uses='jinahub+docker://AdvancedExecutor2')
)
Remote
from jina import Flow
f = (
Flow()
.add(name='encoder',
uses='jinahub+docker://AdvancedExecutor1',
host='1.2.3.4',
port_jinad=8000)
.add(name='indexer',
uses='jinahub+docker://AdvancedExecutor2',
host='2.3.4.5',
port_jinad=8000)
)
File structures with remote Executors
Important
Read the best practices about managing repository structure.
For a simple project structure, for example,
.
├── project
│ ├── config.yml # Defines `py_modules: my_executor.py`
│ └── my_executor.py # Defines MyExecutor
Using YAML
from jina import Flow
PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
f = Flow().add(uses='config.yml',
host='1.2.3.4',
port_jinad=8000,
upload_files=PATH_TO_EXECUTOR_DIRECTORY)
Using py_modules
from jina import Flow
PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
f = Flow().add(uses='MyExecutor',
host='1.2.3.4',
port_jinad=8000,
py_modules='my_executors.py'
upload_files=PATH_TO_EXECUTOR_DIRECTORY)
Suppose you have a complex project structure, for example,
.
├── project
│ ├── config.yml # Defines `py_modules: executors/__init__.py`
│ └── executors
│ ├── __init__.py # Imports MyExecutor from `my_executors.py`
│ ├── helper.py
│ ├── my_executor.py # Defines MyExecutor
│ └── utils
│ ├── __init__.py
│ ├── data.py
│ └── io.py
│ ├── flow.yml
│ ├── requirements-index.txt # Includes your pip dependencies
│ ├── requirements.txt
Using YAML
from jina import Flow
PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
f = Flow().add(uses='config.yml',
host='1.2.3.4',
port_jinad=8000,
upload_files=PATH_TO_EXECUTOR_DIRECTORY)
Using py_modules
from jina import Flow
PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
f = Flow().add(uses='MyExecutor',
host='1.2.3.4',
port_jinad=8000,
py_modules='executors/__init__.py'
upload_files=PATH_TO_EXECUTOR_DIRECTORY)
Hint
Always pass the path to the directory via
upload_files
.Always pass relative filepath wrt to the project in
py_modules
oruses
orconfig.yml
.Keep your
requirements.txt
files on the root level.
Using GPU with any remote Executor
Without GPU
from jina import Flow
f = Flow().add(uses='TFExecutor',
host='1.2.3.4',
port_jinad=8000,
...)
With GPU
from jina import Flow
f = Flow().add(uses='TFExecutor',
host='1.2.3.4',
port_jinad=8000,
...,
gpus='all')