Skip to content

Commit

Permalink
Merge pull request #87 from madflojo/custom-poolsize
Browse files Browse the repository at this point in the history
Adding Custom Poolsize for WASM Functions
  • Loading branch information
madflojo authored Jan 4, 2024
2 parents a3db481 + 0d0312b commit 85cd3de
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
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 @@ func (srv *Server) Run() error {
err = srv.engine.LoadModule(engine.ModuleConfig{
Name: "default",
Filepath: srv.cfg.GetString("wasm_function"),
PoolSize: srv.cfg.GetInt("wasm_pool_size"),
})
if err != nil {
return fmt.Errorf("could not load default function path for wasm_function (%s) - %s", srv.cfg.GetString("wasm_function"), err)
Expand All @@ -599,6 +600,7 @@ func (srv *Server) Run() error {
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)
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

0 comments on commit 85cd3de

Please sign in to comment.