-
Notifications
You must be signed in to change notification settings - Fork 99
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
Filter idea: Scriptable filter #13
Comments
https://mun-lang.org/ looks interesting |
The primary blocker I encountered with adding this to the current implementation is that the |
I'm assuming this speaks to whether we want to support WASM? Or do we instead want to experiment with embedding a scripting language of some kind? |
This applies to any language, if we want to be able to send and receive context across language barriers it needs to be in a format that's safe to copy, and represent across the barriers. This excludes So what that means in practice is that the context metadata needs to be restricted to a limited set of types, essentially what you can represent is numbers, strings, lists, enums, and structs. So an ABI safe context needs to only contain those types (and no generic parameters, you can use generic types but their parameters must be set |
Tested out adding both a lua and rhai script filter iffyio@35d2cef |
Yeah, that's to be expected, I'm interested to see how wasmtime compares, but there's always going to be some slowdown in the process of copying the packet memory into the language VM, maybe with something like |
Two thoughts:
If we did give it up -- does that make some parts of Quilkin simpler for us to design, implement and manage long term? |
Well I don't think not having scripting would affect #346 too much really, as the language FFI bindings as it would just be another set of bindings, and the original motivation of reducing our
Well I'm not sure I see how it isn't useful in general. Not every feature's benefits depend on its performance (Also should note wasmtime is a JIT compiler, where as Lua and rhai are interpreted.) I think scripting is important because it opens the audience of Quilkin developers immensely and makes getting started with the project a lot easier. It's important to keep in mind how much work it would be for users to deploy their custom Quilkin binary for a custom filter versus being able to write a script directly in the YAML that works with the binary that's already available. This discussion also has me thinking that maybe we should consider dynamic library loaded filters to allow you to deploy a custom filter alongside Quilkin instead of needing to build your own Quilkin, but that's for another issue. Irregardless I think having more dynamic high level options to write filters is valuable towards growing the project's community, as in my mind there's no reason for Quilkin to be thought of as a proxy for Rust projects, its potential is far greater. Scripting and in particular using WebAssembly has tonne of advantages to achieving that goal.
So to summarise, while it might make some things simpler, I think we would be giving up a lot of the potential, and would hurt long term adoption of the project by limiting our customisability story to just using Quilkin as a Rust library. |
the reason I looked into this now was because I recently had to patch envoy's filterchain for work and it was so simple to use istio's EnvoyFilter to add a lua script dynamically and I figured it would be really powerful for quilkin too (I definitely wouldn't have wanted to write an envoy filter and maintain our own build of envoy just for that patch, though this process would be a lot simpler with quilkin I think). Maybe we could still have a script filter but release it with a big red warning that it has perf drawbacks and you should test it out on your game first to see if/how-much its affected, because while I can't really see the script filter running on a quilkin loadbalancer, I could imagine it running on a quilkin sidecar since that has less traffic to process (and also on usecases that aren't game-traffic/latency sensitive). Re wasm, I don't know if wasm would be as simple to use or what it would look like so hard to say. e.g how do I go from my writing my |
Definitely, 4x is too much we need something faster, and we should still caveat, I've updated my WASM PR and ran benchmark and I think it's much more reasonable of about 25–30% overhead over having no filter.
So right now, WASM would be harder to use than rula or rhai, because right now we would only support WebAssembly and not a language that compiles to WASM. So you'd need to compile your program to WebAssembly first before running it with Quilkin. I haven't found a nice AOT (Ahead Of Time) language for WASM, I had hoped someone had written a lua2wasm compiler but it seems like no one has yet. (Someone should steal that idea) |
Notes from community meeting:
|
Noting down for later: Envoy now supports WebAssembly and have xDS configuration for it already, another thing that's pushing me towards WebAssembly for this. https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/wasm/v3/wasm.proto#wasm FWIW how they pass configuration is by passing the WASM module a blob of JSON. I think that should be more than enough for us, though we'd want to setup the filter so that it's not passing configuration on every call. I think an API like the following should be more than sufficient. /// Handle is an opaque reference to an instantiatied filter on the WASM side.
type Handle = !;
pub fn quilkin_filter_new(config: Json) -> Handle;
pub fn quilkin_filter_read(handle: &Handle, ctx: ReadContextJson) -> Handle;
pub fn quilkin_filter_write(handle: &Handle, ctx: WriteContextJson) -> Handle; |
Docker and WasmEdge seem to be solution for distribution we're looking for. https://medium.com/@shyamsundarb/exploring-docker-hubs-wasm-technical-preview-76de28c3b1b4 |
(Placeholder, more to work out)
The idea being, we would integrate some kind of scripting langauge into Quilkin, such that if you needed custom filters, you could script them, rather than having to use Quilkin as a library and build your own binaries.
This might tie well into #12 - since scripted filters are expected to be slower than native rust (although worth experimentation).
Useful resources:
The text was updated successfully, but these errors were encountered: