Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Replace Python gRPC with Rust #2328

Closed
1,138 changes: 1,138 additions & 0 deletions flyrs/Cargo.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions flyrs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "flyrs"
version = "0.1.0"
edition = "2021"

[lib]
# The name of the native library. This is the name which will be used in Python to import the
# library (i.e. `import string_sum`). If you change this, you must also change the name of the
# `#[pymodule]` in `src/lib.rs`.
name = "flyrs"
# "cdylib" is necessary to produce a shared library for Python to import from.
crate-type = ["cdylib"]

[dependencies]
prost = "0.12.3"
tonic = "0.11.0"
tokio = { version = "1.37.0", features = ["full"] }
pyo3 = { version = "0.21", features = ["extension-module", "experimental-async"] }
flyteidl = { git="https://github.com/austin362667/flyte.git", branch = "austin362667/flyteidl/rs" }
tower = "0.4.13"

[build-dependencies]

1,061 changes: 1,061 additions & 0 deletions flyrs/clients/friendly.py

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions flyrs/perf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import timeit
import matplotlib.pyplot as plt

setup = """
from flytekit.remote import FlyteRemote;
from remote import RustFlyteRemote;
from flytekit.configuration import Config;
PROJECT = "flytesnacks";
DOMAIN = "development";
remote_py = FlyteRemote(Config.auto(), default_project=PROJECT, default_domain=DOMAIN);
remote_rs = RustFlyteRemote(Config.auto(), default_project=PROJECT, default_domain=DOMAIN);
"""

fetch_task_in_py = """task_py = remote_py.fetch_task(project=PROJECT, domain=DOMAIN, name="workflows_.say_1", version="WhIAnhpyjrAdaRvrQ9Cjpw")"""
fetch_task_in_rs = """task_rs = remote_rs.fetch_task(project=PROJECT, domain=DOMAIN, name="workflows_.say_1", version="WhIAnhpyjrAdaRvrQ9Cjpw")"""

r = 10
Xs = [1, 10, 100, 1000]
py_elpased, rs_elpased = [], []
for x in Xs:
# Python gRPC
py_elpased.append(sum(timeit.repeat(fetch_task_in_py, setup=setup, repeat=r, number=x))/r)
print()
# Rust gRPC
rs_elpased.append(sum(timeit.repeat(fetch_task_in_rs, setup=setup, repeat=r, number=x))/r)
print()
plt.xlabel('# of fetched tasks')
plt.ylabel('average elapsed time (s)')
plt.plot(Xs, py_elpased,'r-',label='Python gRPC')
plt.plot(Xs, rs_elpased,'b-',label='Rust gRPC')
plt.legend()
plt.savefig("perf.png")
12 changes: 12 additions & 0 deletions flyrs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[build-system]
requires = ["maturin>=1,<2"]
build-backend = "maturin"

[project]
name = "flyrs"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
11 changes: 11 additions & 0 deletions flyrs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### How to build Rust FlyteRemote Client?
1. Instal `matruin` to build Python packages with Rust `PyO3`.
- `pip install maturin`
2. Compile Python extension and instal it into local Python virtual environment root.
- `maturin develop`
- or `maturin develop --release` (Pass `--release` to `cargo build`)

### How to test Rust FlyteRemote Client?
1. `pyflyte register ./t.py` to get flyte entity `version` id
2. Set previous fetched `version` id in `./test_flyte_remote.py`'s `VERSION_ID`
2. `pytest ./test_flyte_remote.py` inside `flyrs/`
Loading
Loading