diff --git a/docs/running-tarmac/configuration.md b/docs/running-tarmac/configuration.md index 214693e..2e6a233 100644 --- a/docs/running-tarmac/configuration.md +++ b/docs/running-tarmac/configuration.md @@ -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`)| diff --git a/docs/wasm-functions/multi-function-services.md b/docs/wasm-functions/multi-function-services.md index 475b514..485948f 100644 --- a/docs/wasm-functions/multi-function-services.md +++ b/docs/wasm-functions/multi-function-services.md @@ -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" @@ -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 diff --git a/go.mod b/go.mod index 6815b64..b0e5fe3 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 126d071..351dbad 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/app/app.go b/pkg/app/app.go index 9a6959b..c20bb47 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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) @@ -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) diff --git a/pkg/app/server_test.go b/pkg/app/server_test.go index 448b129..b96cf0b 100644 --- a/pkg/app/server_test.go +++ b/pkg/app/server_test.go @@ -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) { @@ -236,6 +236,7 @@ func TestFullService(t *testing.T) { t.Errorf("Unexpected http status code when making request %d", r.StatusCode) } }) + }) } } diff --git a/pkg/config/config.go b/pkg/config/config.go index f8a64f2..be20cee 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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. diff --git a/testdata/tarmac.json b/testdata/tarmac.json index b3354d6..6a223fc 100644 --- a/testdata/tarmac.json +++ b/testdata/tarmac.json @@ -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": [