Skip to content

Commit

Permalink
Adding a custom pool size for wasm functions
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo committed Jan 4, 2024
1 parent 06eaf88 commit 4767737
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 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
4 changes: 2 additions & 2 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +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"),
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)
Expand All @@ -600,7 +600,7 @@ func (srv *Server) Run() error {
err := srv.engine.LoadModule(engine.ModuleConfig{
Name: fName,
Filepath: fCfg.Filepath,
PoolSize: fCfg.PoolSize,
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
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ 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"`
// 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 4767737

Please sign in to comment.