Tidb: TiDB in WebAssembly WASI

Created on 7 Nov 2019  路  20Comments  路  Source: pingcap/tidb

Feature Request

Describe the feature you'd like:
Following #13069, I think it would be a great idea to compile TiDB to WebAssembly WASI.

This way, there can be a standalone TiDB wasm binary published in WAPM and available in any platform/OS and even online with the WebAssembly shell, so anyone can play with it easily.

Describe alternatives you've considered:
This should be feasible by using the go/wasi implementation.

Teachability, Documentation, Adoption, Migration Strategy:
If this is something that you are interested in, we can help on the implementation :)

componenwasm typenhancement

Most helpful comment

We just fixed the issue, and now tidb runs properly on the WebAssembly shell 馃帀

Note: we are going to release a new version of wasmer soon that will use the singlepass backend automatically when the file size is very big (solving the issue of running tidb with wapm directly).

https://webassembly.sh/?run-command=tidb

Screen Shot 2019-12-09 at 4 53 33 PM

All 20 comments

That's so cool! In fact, we are very eager to do this, but we notice that it seems golang/wasi is still working in progress, I'm not sure if it's possible at the present stage.
We want to have a try, it will be very nice if you can help.

After a few trials I got tidb compiled to WASI:

main.wasm.zip

However, the file is so large I've been unable to run it with any runtime 馃槄

@syrusakbary It seems that we can only run it in PC's browser now, the phone will report out of execution memory:
image
Maybe we can reduce the size by remove some useless functions in tidb when we compile to wasm

maybe we need to fix #13322 at first, to reduce the binary size.

@syrusakbary I try to write a hello world with golang, and run it with wasmer, but failed, I'm not sure if something is wrong.
灞忓箷蹇収 2019-11-14 涓嬪崍3 59 55

@syrusakbary finally I make it work by a modified wasmer:
灞忓箷蹇収 2019-11-25 涓嬪崍7 36 21
I modify one line code:
灞忓箷蹇収 2019-11-25 涓嬪崍7 38 21
I know it's just a workaround, instead of the best way to solve this, but I hope this can help to find the root cause.

You can use this code for testing

Love it! Can you upload the wasm generated file somewhere?

@nlewycky

Also, can you try to run it with wasmer-js and see what's the result? (wasmer-js run main.wasm).

Note: you can install wasmer-js with npm install -g @wasmer/cli;

We debugged this internally, and it might be caused by go/wasi generating an invalid WebAssembly file. Depending on your results on the previous questions we will be able to validate this assumption.

What can be causing the issue? A data element has an address that overflow the end of the memory. If that's the case, this could be easily fixed on the go/wasi side (on the compiler from go to WebAssembly WASI).

The wasm generated file: main.wasm.zip
The result of wasmer-js run main.wasm(the same error with wasmer):
灞忓箷蹇収 2019-11-26 涓婂崍10 44 41

@syrusakbary PTAL

@syrusakbary I have modified go/wasi and I can run tidb with wasmer(without modify). However, I can't run it with wapm neither in the browser nor in the local shell.
The WebAssembly shell log:
灞忓箷蹇収 2019-12-09 涓嬪崍4 37 00
And the wasm file:
main.wasm.zip

We just fixed the issue, and now tidb runs properly on the WebAssembly shell 馃帀

Note: we are going to release a new version of wasmer soon that will use the singlepass backend automatically when the file size is very big (solving the issue of running tidb with wapm directly).

https://webassembly.sh/?run-command=tidb

Screen Shot 2019-12-09 at 4 53 33 PM

Wow, amazing job. Thank you @syrusakbary

@syrusakbary What version the WebAssembly shell will use? There are some bugs in tidb's wasm result and I fixed them, but it seems that the WebAssembly just use an older version in most time (although sometimes it uses newest one)

Perhaps the module is being cached?
Adding @torch2424 to the thread to see what we can do in our side.

@lucklove Hello! 馃槃

So If I could ask, how are you adding the Wasm Module? Are you dragging it in? Or installing it from WAPM?

Thanks! 馃槃 馃憤

@torch2424 I just open WebAssembly Shell and input "tidb" (I think it's installed from WAPM). I expect it uses the newest version, however, it uses old ones.
I also try wapm install tidb@version, it seems it downloaded the specified version, however, when I typed "tidb", it downloads old versions again

Update: I found that it seems webassembly shell store previous downloads in somewhere in the browser so the next time the user input the same command, it doesn't request the network. After clearing cache, it works.

@lucklove

Ah yep! Sorry for not responding earlier, currently on a work trip!

Ah yep, that's a bug, I'll go ahead and open an issue for this, thank you! 馃槃 馃憤

Edit: Opened this issue: https://github.com/wasmerio/webassembly.sh/issues/69

Closing this since TiDB can work well with WASI now.

Was this page helpful?
0 / 5 - 0 ratings