Skip to content
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

Adding Custom Poolsize for WASM Functions #87

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/running-tarmac/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ When using Environment Variables, all configurations are prefixed with `APP_`. T
| `APP_IGNORE_CLIENT_CERT` | `ignore_client_cert` | `string` | When defined will disable Client Cert validation for m-TLS authentication |
| `APP_WASM_FUNCTION` | `wasm_function` | `string` | Path and Filename of the WASM Function to execute \(Default: `/functions/tarmac.wasm`\) |
| `APP_WASM_FUNCTION_CONFIG` | `wasm_function_config` | `string` | Path to Service configuration for multi-function services \(Default: `/functions/tarmac.json`\) |
| `APP_WASM_POOL_SIZE` | `wasm_pool_size` | `int` | Number of WASM function instances to create \(Default: `100`\). Only applicable when `wasm_function` is used. |
| `APP_ENABLE_PPROF` | `enable_pprof` | `bool` | Enable PProf Collection HTTP end-points |
| `APP_ENABLE_KVSTORE` | `enable_kvstore` | `bool` | Enable the KV Store |
| `APP_KVSTORE_TYPE` | `kvstore_type` | `string` | Select KV Store to use (Options: `redis`, `cassandra`, `boltdb`, `in-memory`, `internal`)|
Expand Down
5 changes: 3 additions & 2 deletions docs/wasm-functions/multi-function-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ The `tarmac.json` file has a simple structure that consists of a single object w
"name": "my-service",
"functions": {
"function1": {
"filepath": "/path/to/function1.wasm"
"filepath": "/path/to/function1.wasm",
"pool_size": 10
},
"function2": {
"filepath": "/path/to/function2.wasm"
Expand Down Expand Up @@ -61,7 +62,7 @@ The functions object contains one or more key-value pairs, with each key represe
Each function object should include the following properties:

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

#### Routes

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.18.2
github.com/tarmac-project/wapc-toolkit v0.1.0
github.com/tarmac-project/wapc-toolkit v0.1.1
github.com/wapc/wapc-go v0.6.2
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tarmac-project/wapc-toolkit v0.1.0 h1:GbL3SqbgD0O4aSX2GdxDiu/g1tqNxCR/eQF4wOKtLbQ=
github.com/tarmac-project/wapc-toolkit v0.1.0/go.mod h1:3u2DX1cOveIKuYVL3hmD9lkFbF2HVVfYTpF6Y17cWBo=
github.com/tarmac-project/wapc-toolkit v0.1.1 h1:Mp4C8Iv9mHMkCLOzXjmWbjUsVwUp5QO+GmZm0tQU2L0=
github.com/tarmac-project/wapc-toolkit v0.1.1/go.mod h1:3u2DX1cOveIKuYVL3hmD9lkFbF2HVVfYTpF6Y17cWBo=
github.com/tetratelabs/wazero v1.5.0 h1:Yz3fZHivfDiZFUXnWMPUoiW7s8tC1sjdBtlJn08qYa0=
github.com/tetratelabs/wazero v1.5.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg=
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@
err = srv.engine.LoadModule(engine.ModuleConfig{
Name: "default",
Filepath: srv.cfg.GetString("wasm_function"),
PoolSize: srv.cfg.GetInt("wasm_pool_size"),

Check warning on line 578 in pkg/app/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/app.go#L578

Added line #L578 was not covered by tests
})
if err != nil {
return fmt.Errorf("could not load default function path for wasm_function (%s) - %s", srv.cfg.GetString("wasm_function"), err)
madflojo marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -599,6 +600,7 @@
err := srv.engine.LoadModule(engine.ModuleConfig{
Name: fName,
Filepath: fCfg.Filepath,
PoolSize: fCfg.PoolSize,
})
if err != nil {
return fmt.Errorf("could not load function %s from path %s - %s", fName, fCfg.Filepath, err)
madflojo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestFullService(t *testing.T) {
defer srv.Stop()

// Wait for Server to start
time.Sleep(10 * time.Second)
time.Sleep(30 * time.Second)

// Call /logger with POST
t.Run("Do a Post on /logger", func(t *testing.T) {
Expand Down Expand Up @@ -236,6 +236,7 @@ func TestFullService(t *testing.T) {
t.Errorf("Unexpected http status code when making request %d", r.StatusCode)
}
})

})
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type Service struct {
type Function struct {
// Filepath to the WASM function
Filepath string `json:"filepath"`

// PoolSize defines the number of instances of the function to create
PoolSize int `json:"pool_size"`
}

// Route defines available routes for the service.
Expand Down
9 changes: 6 additions & 3 deletions testdata/tarmac.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
"filepath": "/testdata/default/tarmac.wasm"
},
"kv": {
"filepath": "/testdata/kv/tarmac.wasm"
"filepath": "/testdata/kv/tarmac.wasm",
"pool_size": 1000
},
"logger": {
"filepath": "/testdata/logger/tarmac.wasm"
},
"sql": {
"filepath": "/testdata/sql/tarmac.wasm"
"filepath": "/testdata/sql/tarmac.wasm",
"pool_size": 10
},
"func": {
"filepath": "/testdata/function/tarmac.wasm"
"filepath": "/testdata/function/tarmac.wasm",
"pool_size": 1
}
},
"routes": [
Expand Down