Skip to content

Commit 85cd3de

Browse files
authored
Merge pull request #87 from madflojo/custom-poolsize
Adding Custom Poolsize for WASM Functions
2 parents a3db481 + 0d0312b commit 85cd3de

File tree

8 files changed

+20
-7
lines changed

8 files changed

+20
-7
lines changed

docs/running-tarmac/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ When using Environment Variables, all configurations are prefixed with `APP_`. T
2626
| `APP_IGNORE_CLIENT_CERT` | `ignore_client_cert` | `string` | When defined will disable Client Cert validation for m-TLS authentication |
2727
| `APP_WASM_FUNCTION` | `wasm_function` | `string` | Path and Filename of the WASM Function to execute \(Default: `/functions/tarmac.wasm`\) |
2828
| `APP_WASM_FUNCTION_CONFIG` | `wasm_function_config` | `string` | Path to Service configuration for multi-function services \(Default: `/functions/tarmac.json`\) |
29+
| `APP_WASM_POOL_SIZE` | `wasm_pool_size` | `int` | Number of WASM function instances to create \(Default: `100`\). Only applicable when `wasm_function` is used. |
2930
| `APP_ENABLE_PPROF` | `enable_pprof` | `bool` | Enable PProf Collection HTTP end-points |
3031
| `APP_ENABLE_KVSTORE` | `enable_kvstore` | `bool` | Enable the KV Store |
3132
| `APP_KVSTORE_TYPE` | `kvstore_type` | `string` | Select KV Store to use (Options: `redis`, `cassandra`, `boltdb`, `in-memory`, `internal`)|

docs/wasm-functions/multi-function-services.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The `tarmac.json` file has a simple structure that consists of a single object w
1717
"name": "my-service",
1818
"functions": {
1919
"function1": {
20-
"filepath": "/path/to/function1.wasm"
20+
"filepath": "/path/to/function1.wasm",
21+
"pool_size": 10
2122
},
2223
"function2": {
2324
"filepath": "/path/to/function2.wasm"
@@ -61,7 +62,7 @@ The functions object contains one or more key-value pairs, with each key represe
6162
Each function object should include the following properties:
6263

6364
- `filepath`: The file path to the .wasm file containing the function code (required).
64-
- `configuration`: An optional object containing configuration data for the function.
65+
- `pool_size`: The number of instances of the function to create (optional). Defaults to 100.
6566

6667
#### Routes
6768

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/prometheus/client_golang v1.18.0
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/spf13/viper v1.18.2
16-
github.com/tarmac-project/wapc-toolkit v0.1.0
16+
github.com/tarmac-project/wapc-toolkit v0.1.1
1717
github.com/wapc/wapc-go v0.6.2
1818
)
1919

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
324324
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
325325
github.com/tarmac-project/wapc-toolkit v0.1.0 h1:GbL3SqbgD0O4aSX2GdxDiu/g1tqNxCR/eQF4wOKtLbQ=
326326
github.com/tarmac-project/wapc-toolkit v0.1.0/go.mod h1:3u2DX1cOveIKuYVL3hmD9lkFbF2HVVfYTpF6Y17cWBo=
327+
github.com/tarmac-project/wapc-toolkit v0.1.1 h1:Mp4C8Iv9mHMkCLOzXjmWbjUsVwUp5QO+GmZm0tQU2L0=
328+
github.com/tarmac-project/wapc-toolkit v0.1.1/go.mod h1:3u2DX1cOveIKuYVL3hmD9lkFbF2HVVfYTpF6Y17cWBo=
327329
github.com/tetratelabs/wazero v1.5.0 h1:Yz3fZHivfDiZFUXnWMPUoiW7s8tC1sjdBtlJn08qYa0=
328330
github.com/tetratelabs/wazero v1.5.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
329331
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=

pkg/app/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ func (srv *Server) Run() error {
575575
err = srv.engine.LoadModule(engine.ModuleConfig{
576576
Name: "default",
577577
Filepath: srv.cfg.GetString("wasm_function"),
578+
PoolSize: srv.cfg.GetInt("wasm_pool_size"),
578579
})
579580
if err != nil {
580581
return fmt.Errorf("could not load default function path for wasm_function (%s) - %s", srv.cfg.GetString("wasm_function"), err)
@@ -599,6 +600,7 @@ func (srv *Server) Run() error {
599600
err := srv.engine.LoadModule(engine.ModuleConfig{
600601
Name: fName,
601602
Filepath: fCfg.Filepath,
603+
PoolSize: fCfg.PoolSize,
602604
})
603605
if err != nil {
604606
return fmt.Errorf("could not load function %s from path %s - %s", fName, fCfg.Filepath, err)

pkg/app/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestFullService(t *testing.T) {
179179
defer srv.Stop()
180180

181181
// Wait for Server to start
182-
time.Sleep(10 * time.Second)
182+
time.Sleep(30 * time.Second)
183183

184184
// Call /logger with POST
185185
t.Run("Do a Post on /logger", func(t *testing.T) {
@@ -236,6 +236,7 @@ func TestFullService(t *testing.T) {
236236
t.Errorf("Unexpected http status code when making request %d", r.StatusCode)
237237
}
238238
})
239+
239240
})
240241
}
241242
}

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type Service struct {
3939
type Function struct {
4040
// Filepath to the WASM function
4141
Filepath string `json:"filepath"`
42+
43+
// PoolSize defines the number of instances of the function to create
44+
PoolSize int `json:"pool_size"`
4245
}
4346

4447
// Route defines available routes for the service.

testdata/tarmac.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
"filepath": "/testdata/default/tarmac.wasm"
88
},
99
"kv": {
10-
"filepath": "/testdata/kv/tarmac.wasm"
10+
"filepath": "/testdata/kv/tarmac.wasm",
11+
"pool_size": 1000
1112
},
1213
"logger": {
1314
"filepath": "/testdata/logger/tarmac.wasm"
1415
},
1516
"sql": {
16-
"filepath": "/testdata/sql/tarmac.wasm"
17+
"filepath": "/testdata/sql/tarmac.wasm",
18+
"pool_size": 10
1719
},
1820
"func": {
19-
"filepath": "/testdata/function/tarmac.wasm"
21+
"filepath": "/testdata/function/tarmac.wasm",
22+
"pool_size": 1
2023
}
2124
},
2225
"routes": [

0 commit comments

Comments
 (0)