connect icon indicating copy to clipboard operation
connect copied to clipboard

Play with a WASM processor

Open Jeffail opened this issue 3 years ago • 2 comments

We should do a bit of explorative work and see how easily a WASM processor using https://github.com/suborbital/reactr would be.

Jeffail avatar Nov 24 '21 20:11 Jeffail

tinygo was recently added, so it makes it much easier to test 👍 https://github.com/suborbital/reactr/tree/main/rwasm/testdata/tinygo-req

gedw99 avatar Nov 25 '21 16:11 gedw99

I know that there are exec type extensibility for inputs, processors, and outputs but the contract for these things are more expressive than a fifo of bytes, as the stdin/stdout interface of subprocess is.

This would make the flexibility of benthos endless, and let orgs more comfortable in other languages be able to use benthos as a platform for their code with lower entry cost. The full interface exposed in the public/service package can be exposed to the WASM implementation, and the WASM blob can be accessed from object store or whatever, which is a big advantage over building a go program to extend benthos.

Nothing new in this comment, just agreeing mostly. :)

iluminae avatar Apr 11 '22 14:04 iluminae

I'm also very interested in WASM. I come from a Rust and JS background, and being able to write a WASM plugin would just be ideal.

The bytecode alliance have just released v1 of wasmtime, which will be a massive milestone for WASM and WASI. In a nutshell, startup time for a WASM invocation is now down to 5 microseconds.

There is a wasmtime-go package for easily embedding in a Go a program

cortopy avatar Sep 28 '22 09:09 cortopy

Hey @cortopy, I forgot to update this ticket but there's an experimental WASI plugin implemented on this branch: https://github.com/benthosdev/benthos/tree/wasmtime-go, performance isn't amazing as we're having to pipe data to/from files but it's a starting point.

Jeffail avatar Sep 28 '22 09:09 Jeffail

thanks @Jeffail !!! That sounds amazing!!

cortopy avatar Sep 29 '22 17:09 cortopy

Cool stuff

Which WASI runtime is used ??

gedw99 avatar Sep 29 '22 17:09 gedw99

Ok it’s wasmtine. Was hoping it’s Wazero so there is zero cgo overhead / complications.

https://github.com/tetratelabs/wazero

gedw99 avatar Sep 29 '22 17:09 gedw99

@gedw99 wazero is literally the next thing I'm going to try, will aim to have both to choose from.

Jeffail avatar Sep 29 '22 20:09 Jeffail

@gedw99 wazero is literally the next thing I'm going to try, will aim to have both to choose from.

Also checkout Capsule that uses Wazero and NATS together . I was thinking of adding Benthos into that stack for all data transforms.

All Actions are Sent to NATS workers ( wasm ) and benthos does any data transform required via a NATS stream topic.

The mutated data goes back into NATS out of Benthos kicking off another Benthos transform. Infinite recursion….

The key space in NATS is your address system.

You end up with a Google sheets self hosted. You get parametric recursion just like Google Sheets.

gedw99 avatar Oct 02 '22 09:10 gedw99

Okay so I've put together a wasm processor using wazero so we still avoid the cgo dependencies: https://github.com/benthosdev/benthos/commit/da7179aefb1d7dd32dc34a7e7243adab73f8be28, I decided in the end to implement helper functions for accessing/mutating message data. We'll need to expand the exported functions and grow the number of language examples but the basics are there and ready to try.

Closing this issue for now as the experimentation is concluded.

Jeffail avatar Nov 15 '22 21:11 Jeffail

@Jeffail no CGO !!! that code looks really good.

if there is any examples ? would love to have a play..

gedw99 avatar Jan 03 '23 13:01 gedw99

@gedw99 Have a look here: https://github.com/benthosdev/benthos/tree/main/public/wasm I'm thinking to give Python a shot, but it looks like that might require some more work.

mihaitodor avatar Jan 03 '23 14:01 mihaitodor

thansk @mihaitodor will look now..

am glad i dont have to do python to wasm.. But would be interesting to see if its works.

gedw99 avatar Jan 03 '23 14:01 gedw99