Remote Executors

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

Executors from Hub

Local (jinahub+docker)

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

Remote (jinahub+docker)

  1. from jina import Flow
  2. f = Flow().add(uses='jinahub+docker://AdvancedExecutor',
  3. host='1.2.3.4',
  4. port_jinad=8000)

Local (jinahub)

  1. from jina import Flow
  2. f = Flow().add(uses='jinahub://AdvancedExecutor',
  3. install_requirements=True)

Remote (jinahub)

  1. from jina import Flow
  2. f = Flow().add(uses='jinahub://AdvancedExecutor',
  3. install_requirements=True,
  4. host='1.2.3.4',
  5. port_jinad=8000)

Executors on different hosts

Local

  1. from jina import Flow
  2. f = (
  3. Flow()
  4. .add(name='encoder',
  5. uses='jinahub+docker://AdvancedExecutor1')
  6. .add(name='indexer',
  7. uses='jinahub+docker://AdvancedExecutor2')
  8. )

Remote

  1. from jina import Flow
  2. f = (
  3. Flow()
  4. .add(name='encoder',
  5. uses='jinahub+docker://AdvancedExecutor1',
  6. host='1.2.3.4',
  7. port_jinad=8000)
  8. .add(name='indexer',
  9. uses='jinahub+docker://AdvancedExecutor2',
  10. host='2.3.4.5',
  11. port_jinad=8000)
  12. )

File structures with remote Executors

Important

Read the best practices about managing repository structure.

For a simple project structure, for example,

  1. .
  2. ├── project
  3. ├── config.yml # Defines `py_modules: my_executor.py`
  4. └── my_executor.py # Defines MyExecutor

Using YAML

  1. from jina import Flow
  2. PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
  3. f = Flow().add(uses='config.yml',
  4. host='1.2.3.4',
  5. port_jinad=8000,
  6. upload_files=PATH_TO_EXECUTOR_DIRECTORY)

Using py_modules

  1. from jina import Flow
  2. PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
  3. f = Flow().add(uses='MyExecutor',
  4. host='1.2.3.4',
  5. port_jinad=8000,
  6. py_modules='my_executors.py'
  7. upload_files=PATH_TO_EXECUTOR_DIRECTORY)

Suppose you have a complex project structure, for example,

  1. .
  2. ├── project
  3. ├── config.yml # Defines `py_modules: executors/__init__.py`
  4. └── executors
  5. ├── __init__.py # Imports MyExecutor from `my_executors.py`
  6. ├── helper.py
  7. ├── my_executor.py # Defines MyExecutor
  8. └── utils
  9. ├── __init__.py
  10. ├── data.py
  11. └── io.py
  12. ├── flow.yml
  13. ├── requirements-index.txt # Includes your pip dependencies
  14. ├── requirements.txt

Using YAML

  1. from jina import Flow
  2. PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
  3. f = Flow().add(uses='config.yml',
  4. host='1.2.3.4',
  5. port_jinad=8000,
  6. upload_files=PATH_TO_EXECUTOR_DIRECTORY)

Using py_modules

  1. from jina import Flow
  2. PATH_TO_EXECUTOR_DIRECTORY = '/path/to/project/directory'
  3. f = Flow().add(uses='MyExecutor',
  4. host='1.2.3.4',
  5. port_jinad=8000,
  6. py_modules='executors/__init__.py'
  7. upload_files=PATH_TO_EXECUTOR_DIRECTORY)

Hint

  1. Always pass the path to the directory via upload_files.

  2. Always pass relative filepath wrt to the project in py_modules or uses or config.yml.

  3. Keep your requirements.txt files on the root level.

Using GPU with any remote Executor

Without GPU

  1. from jina import Flow
  2. f = Flow().add(uses='TFExecutor',
  3. host='1.2.3.4',
  4. port_jinad=8000,
  5. ...)

With GPU

  1. from jina import Flow
  2. f = Flow().add(uses='TFExecutor',
  3. host='1.2.3.4',
  4. port_jinad=8000,
  5. ...,
  6. gpus='all')