Skip to content

Commit b3aed62

Browse files
rayowangseefloodzhenjunMa
authored
feat: Layotto Faas engine integrate with wasmtime (#833)
Co-authored-by: seeflood <[email protected]> Co-authored-by: Marco <[email protected]> Fixes #732
1 parent 001cc6f commit b3aed62

File tree

27 files changed

+1305
-94
lines changed

27 files changed

+1305
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ demo/state/common/client
6565
etc/script/mdx
6666
etcd
6767
layotto_wasmer
68+
layotto_wasmtime
6869
nohup.out
6970
/demo/lock/common/client
7071
/demo/secret/common/client

cmd/layotto/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ import (
168168
"mosn.io/layotto/pkg/runtime"
169169
_ "mosn.io/layotto/pkg/wasm"
170170
_ "mosn.io/layotto/pkg/wasm/install"
171+
_ "mosn.io/layotto/pkg/wasm/runtime/wasmtime"
171172
_ "mosn.io/layotto/pkg/wasm/uninstall"
172173
_ "mosn.io/layotto/pkg/wasm/update"
173174

demo/faas/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@
6666
"name": "function1",
6767
"instance_num": 1,
6868
"vm_config": {
69-
"engine": "wasmer",
69+
"engine": "wasmtime",
7070
"path": "demo/faas/code/golang/client/function_1.wasm"
7171
}
7272
},
7373
"function2": {
7474
"name": "function2",
7575
"instance_num": 1,
7676
"vm_config": {
77-
"engine": "wasmer",
77+
"engine": "wasmtime",
7878
"path": "demo/faas/code/golang/server/function_2.wasm"
7979
}
8080
}
@@ -188,4 +188,4 @@
188188
}
189189
}]
190190
}
191-
}
191+
}

docs/en/start/faas/start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Restart containerd for the latest configuration to take effect
9090
sudo systemctl restart containerd
9191
```
9292

93-
#### F、Install wasmer
93+
#### F、Install wasmer (If the vm engine uses wasmer, you need to execute the following command)
9494

9595
```
9696
> curl -L -O https://github.com/wasmerio/wasmer/releases/download/2.0.0/wasmer-linux-amd64.tar.gz

docs/en/start/wasm/start.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ The result is:
6060
#### step 2. start Layotto server
6161
Build:
6262

63-
```shell @if.not.exist layotto_wasmer
64-
go build -tags wasmer -o ./layotto_wasmer ./cmd/layotto
63+
```shell @if.not.exist layotto_wasmtime
64+
go build -tags wasmcomm,wasmtime -o ./layotto_wasmtime ./cmd/layotto
6565
```
6666

67+
if you want to use wasmer as WebAssembly Runtime, please use build command as: `go build -tags wasmcomm,wasmer -o ./layotto_wasmtime ./cmd/layotto`
68+
6769
Run it:
6870

6971
```shell @background
70-
./layotto_wasmer start -c ./demo/faas/config.json
72+
./layotto_wasmtime start -c ./demo/faas/config.json
7173
```
7274

7375
**Note: You need to modify the redis address as needed, the default address is: localhost:6379**
@@ -103,21 +105,23 @@ We can specify the WASM file to be loaded in `./demo/faas/config.json` config fi
103105
"name": "function1",
104106
"instance_num": 1,
105107
"vm_config": {
106-
"engine": "wasmer",
108+
"engine": "wasmtime",
107109
"path": "demo/faas/code/golang/client/function_1.wasm"
108110
}
109111
},
110112
"function2": {
111113
"name": "function2",
112114
"instance_num": 1,
113115
"vm_config": {
114-
"engine": "wasmer",
116+
"engine": "wasmtime",
115117
"path": "demo/faas/code/golang/server/function_2.wasm"
116118
}
117119
}
118120
}
119121
```
120122

123+
tip: we also support wasmer as the engine value in vm_config.
124+
121125
We can also install, update, and uninstall WASM file dynamically through the following Apis(The example is already loaded from the configuration file by default when it starts, so here it is unloaded and then reloaded).
122126

123127
#### Uninstall
@@ -129,7 +133,7 @@ curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -
129133
#### Install
130134

131135
```shell
132-
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"id_1","instance_num":1,"vm_config":{"engine":"wasmer","path":"demo/faas/code/golang/client/function_1.wasm"}}' http://127.0.0.1:34998/wasm/install
136+
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"id_1","instance_num":1,"vm_config":{"engine":"wasmtime","path":"demo/faas/code/golang/client/function_1.wasm"}}' http://127.0.0.1:34998/wasm/install
133137
```
134138

135139
#### Update Instance Number

docs/zh/start/faas/start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Layotto支持加载并运行以 wasm 为载体的 Function,并支持Function
9090
sudo systemctl restart containerd
9191
```
9292

93-
#### F、安装 wasmer
93+
#### F、安装 wasmer(如果vm engine 使用 wasmer 则执行如下命令)
9494

9595
```
9696
> curl -L -O https://github.com/wasmerio/wasmer/releases/download/2.0.0/wasmer-linux-amd64.tar.gz

docs/zh/start/wasm/start.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ docker exec -i redis-test redis-cli get book1
5858

5959
构建:
6060

61-
```shell @if.not.exist layotto_wasmer
62-
go build -tags wasmer -o ./layotto_wasmer ./cmd/layotto
61+
```shell @if.not.exist layotto_wasmtime
62+
go build -tags wasmcomm,wasmtime -o ./layotto_wasmtime ./cmd/layotto
6363
```
6464

65+
如果你想使用 wasmer 作为 WebAssembly 运行时, 可以修改 build 指令为: `go build -tags wasmcomm,wasmer -o ./layotto_wasmtime ./cmd/layotto`
66+
6567
运行:
6668

6769
```shell @background
68-
./layotto_wasmer start -c ./demo/faas/config.json
70+
./layotto_wasmtime start -c ./demo/faas/config.json
6971
```
7072

7173
**注:需要把`./demo/faas/config.json`中的 redis 地址修改为实际地址,默认地址为:localhost:6379。**
@@ -100,21 +102,23 @@ docker rm -f redis-test
100102
"name": "function1",
101103
"instance_num": 1,
102104
"vm_config": {
103-
"engine": "wasmer",
105+
"engine": "wasmtime",
104106
"path": "demo/faas/code/golang/client/function_1.wasm"
105107
}
106108
},
107109
"function2": {
108110
"name": "function2",
109111
"instance_num": 1,
110112
"vm_config": {
111-
"engine": "wasmer",
113+
"engine": "wasmtime",
112114
"path": "demo/faas/code/golang/server/function_2.wasm"
113115
}
114116
}
115117
}
116118
```
117119

120+
提示:我们还支持将 wasmer 作为 vm_config 中的 engine 的值。
121+
118122
我们也可通过以下接口来动态的卸载、加载、更新WASM 文件(由于示例启动时已经默认从配置文件中加载,故此处先卸载再加载)。
119123

120124
#### 卸载
@@ -126,7 +130,7 @@ curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -
126130
#### 加载
127131

128132
```shell
129-
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"id_1","instance_num":1,"vm_config":{"engine":"wasmer","path":"demo/faas/code/golang/client/function_1.wasm"}}' http://127.0.0.1:34998/wasm/install
133+
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"id_1","instance_num":1,"vm_config":{"engine":"wasmtime","path":"demo/faas/code/golang/client/function_1.wasm"}}' http://127.0.0.1:34998/wasm/install
130134
```
131135

132136
#### 更新实例数

etc/script/test-quickstart.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sh etc/script/download_etcd.sh
6161
# release all resources
6262
release_resource() {
6363
# kill processes
64-
processes="layotto layotto_wasmer etcd server client go"
64+
processes="layotto layotto_wasmtime etcd server client go"
6565
for key in ${processes}; do
6666
if killall $key; then
6767
echo "$key released"

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module mosn.io/layotto
33
go 1.14
44

55
require (
6-
github.com/99designs/keyring v1.2.1 // indirect
76
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
87
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
98
github.com/Azure/go-autorest/logger v0.2.1 // indirect
109
github.com/SkyAPM/go2sky v0.5.0
1110
github.com/agrea/ptr v0.0.0-20180711073057-77a518d99b7b
1211
github.com/alicebob/miniredis/v2 v2.16.0
12+
github.com/bytecodealliance/wasmtime-go v0.40.0
1313
github.com/dapr/components-contrib v1.5.2
1414
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233
1515
github.com/dimchansky/utfbom v1.1.1 // indirect
@@ -28,11 +28,13 @@ require (
2828
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
2929
github.com/pkg/errors v0.9.1
3030
github.com/shirou/gopsutil v3.21.3+incompatible
31-
github.com/stretchr/testify v1.7.0
31+
github.com/stretchr/testify v1.8.0
3232
github.com/uber/jaeger-client-go v2.25.0+incompatible
3333
github.com/urfave/cli v1.22.1
3434
github.com/valyala/fasthttp v1.28.0
3535
go.uber.org/automaxprocs v1.4.0 // indirect
36+
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect
37+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
3638
golang.org/x/tools v0.1.10 // indirect
3739
google.golang.org/grpc v1.39.0
3840
google.golang.org/grpc/examples v0.0.0-20210818220435-8ab16ef276a3
@@ -47,6 +49,8 @@ require (
4749
)
4850

4951
replace (
52+
github.com/Shopify/sarama => github.com/Shopify/sarama v1.24.0
53+
github.com/apache/pulsar-client-go => github.com/apache/pulsar-client-go v0.1.0
5054
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
5155
github.com/klauspost/compress => github.com/klauspost/compress v1.13.0
5256
mosn.io/layotto/components => ./components

0 commit comments

Comments
 (0)