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

refactor(smartengine): add abstraction layer for WASM engine #3257

Closed
wants to merge 33 commits into from

Conversation

xxchan
Copy link
Contributor

@xxchan xxchan commented May 15, 2023

This PR contains:

  • refactor to add an abstraction layer of wasm engine. And refactor wasmtime engine to use the common code.
  • add WasmEdge engine

To run WasmEdge test, install wasmedge: https://wasmedge.org/book/en/quick_start/install.html
cargo test -p fluvio-smartengine --features wasmedge-engine

I'd like to gain feedbacks about the overall design first. If the general ideas look good, we can take a deeper look and begin to resolve other points (e.g., styling, CI, ...), and maybe split into smaller PRs if necessary.

Some notes:

  • Most code & tests are shared by both engines. Only folder wasmedge is WasmEdge-specific code, and that's ~300 lines of simple code. To discuss how to maintain WasmEdge related code, and to get the ideas of how the common code work, it might be better to keep WasmEdge related code now. This can actually make it easier to review this PR. I can remove the WasmEdge related code after the code review if that's not decided.
  • Since there are some re-org. Maybe it's easier to review by checking out the branch and review locally. (Just a suggestion)

@xxchan xxchan changed the title feat(smartengine): support WasmEdge as an alternative engine [DEMO] feat(smartengine): support WasmEdge as an alternative engine May 15, 2023
@xxchan xxchan force-pushed the xxchan/wasmedge branch from e8270bb to 8f7b787 Compare May 15, 2023 18:58
@xxchan xxchan force-pushed the xxchan/wasmedge branch from 8f7b787 to e6f7e2e Compare May 15, 2023 19:31
@sehz
Copy link
Contributor

sehz commented May 16, 2023

Nice work on adding WasmEdge features. To make it easier to review, can you split these into two separate PR: (1) non WasEdge related changes so we can merge that (2) WasEdge related code. We still have to figure out how to support WasEdge features with minimum impact to Fluvio developers

@xxchan
Copy link
Contributor Author

xxchan commented May 16, 2023 via email

@xxchan xxchan changed the title [DEMO] feat(smartengine): support WasmEdge as an alternative engine refactor(smartengine): add abstraction layer for WASM engine May 31, 2023
@xxchan
Copy link
Contributor Author

xxchan commented May 31, 2023

WasmEdge code is removed.

@xxchan
Copy link
Contributor Author

xxchan commented May 31, 2023

can you reorder terms in of:

  • std
  • third party
  • fluvio dep

xxchan#1 (comment)

@sehz Just FYI, there's a rustfmt option (unstable) https://rust-lang.github.io/rustfmt/?version=v1.5.1&search=#group_imports

I added

group_imports = "StdExternalCrate"

and run

cargo +nightly fmt -p fluvio-smartengine 

Not sure whether you want it for the whole repo, as you use stable toolchian.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes common/init.rs

}

impl SmartModuleInstance {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes to common/mod.rs

}
}

pub(crate) trait SmartModuleTransform: Send + Sync {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes to common/transforms/mod.rs

[dependencies]
tracing ={ workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true, features = ['derive'] }
# std is needed for ser/de AtomicU64
serde = { workspace = true, features = ['derive', 'std'] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously std features is depended by wasmtime, I added it when developing WasmEdge


/// Building SmartModule
#[derive(Default)]
pub struct SmartModuleChainBuilder {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes src/engine/mod.rs

I: WasmInstance,
F: WasmFn<Context = I::Context>,
{
let (ptr, len, version) = instance.write_input(&input, ctx)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prev version used slice abstraction. is there a reason for changing this?

&mut self,
input: &E,
ctx: &mut Self::Context,
) -> Result<(i32, i32, i32)>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use slice abstraction as before

@github-actions
Copy link

Stale pull request message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants