Comments (5)
Closing this since it works now in 0.4!
from extism.
This might be relevant: https://users.rust-lang.org/t/solved-how-to-move-non-send-between-threads-or-an-alternative/19928/7
Sorry, only have time for a quick review but thought that link might be helpful - can dig in more soon. But plugins have their own mutable memory used to persist plugin data between function calls. See https://extism.org/docs/write-a-plugin/rust-pdk/#using-config-io--persisted-variables
Can you create a new plugin context & plugin per spawned task / thread?
from extism.
I have been experimenting with extism and tokio.
The first such experiment, in an axum
program was the following. NOTE: This is all experimental code. Its just meant to provide a slightly more concrete example than simply saying, "use a once_cell". https://docs.rs/once_cell/latest/once_cell/
struct PluginManager {}
impl PluginManager {
fn run(&self, input: String) -> String {
let wasm = std::fs::read("src/code.wasm").unwrap();
let context = Context::new();
let mut plugin = Plugin::new(&context, wasm, vec![], true).unwrap();
let data = plugin.call("count_vowels", &input).unwrap();
String::from_utf8(data.to_vec()).unwrap_or("error".to_string())
}
}
Then in main.rs
:
static PLUGIN_MANAGER: OnceCell<PluginManager> = OnceCell::new();
And before I start the axum server:
let _ = PLUGIN_MANAGER.set(PluginManager {});
Now in any route I can simply:
let plugins = PLUGIN_MANAGER.get().expect("failed to get plugin manager, was it set?");
let result = plugins.run("input");
The next experiment is to update the PluginManager
to separate plugin compilation from execution. If there isn't an obvious way to do this with the once_cell alone I will likely incorporate a https://github.com/xacrimon/dashmap as they allow you to safely update across threads.
from extism.
Yeah I was thinking of using a similar approach. Basically have a plugin registry singleton using OnceCell
.
from extism.
Thanks for following up!
from extism.
Related Issues (20)
- Regression: Can't cancel multiple calls for the same plugin instance HOT 1
- Implement Java PDK HOT 1
- The runtime only returns a generic error when calling `extism_plugin_error` HOT 1
- Improve MSVC support HOT 5
- via proto conversation: refine extism error message when plugin calls fail
- via proto conversation: add example of using extism+tracing to rust runtime HOT 1
- Build linux libextism on manylinux/musllinux containers HOT 8
- Add extism_load_v128/extism_store_v128
- Double mutable borrow issue for `host_fn` with Rust SDK HOT 4
- Error when passing an empty String from Plugin to Runtime via a host function or a logging macro HOT 3
- Add building and installing cmake config mode package
- [Question] How to reload plugin with new wasm file? HOT 6
- extism_length returns garbage values when an ExtismPointer is not aligned with an alloc HOT 1
- feature: Give users a way to manage timeouts from inside host functions HOT 3
- [Question] nodejs call rust wasm function failed. HOT 2
- [Question] C plugin example build failed HOT 2
- Consider reverting `length` safety improvement HOT 3
- sdk: consider switching away from null terminated strings to ptr and length HOT 1
- runtime: update `Plugin::function_extists` and `extism_plugin_function_exists` to check the type of the functions too HOT 4
- derive that forwards From/ToBytes to specific encoding HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extism.