diff --git a/go.mod b/go.mod index 11c5d741..1dd43237 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/suborbital/e2core go 1.19 require ( - github.com/bytecodealliance/wasmtime-go v1.0.0 + github.com/bytecodealliance/wasmtime-go/v5 v5.0.0 github.com/google/uuid v1.3.0 github.com/gorilla/websocket v1.5.0 github.com/nats-io/nats.go v1.23.0 diff --git a/go.sum b/go.sum index 3a480a56..32c5bfaa 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,8 @@ github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7 github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8= github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50= github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= -github.com/bytecodealliance/wasmtime-go v1.0.0 h1:9u9gqaUiaJeN5IoD1L7egD8atOnTGyJcNp8BhkL9cUU= -github.com/bytecodealliance/wasmtime-go v1.0.0/go.mod h1:jjlqQbWUfVSbehpErw3UoWFndBXRRMvfikYH6KsCwOg= +github.com/bytecodealliance/wasmtime-go/v5 v5.0.0 h1:Ue3eBDElMrdzWoUtr7uPr7NeDZriuR5oIivp5EHknQU= +github.com/bytecodealliance/wasmtime-go/v5 v5.0.0/go.mod h1:KcecyOqumZrvLnlaEIMFRbBaQeUYNvsbPjAEVho1Fcs= github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= diff --git a/sat/engine2/runtime/instance/instance.go b/sat/engine2/runtime/instance/instance.go index 4be13e2a..37e2d04c 100644 --- a/sat/engine2/runtime/instance/instance.go +++ b/sat/engine2/runtime/instance/instance.go @@ -1,7 +1,7 @@ package instance import ( - "github.com/bytecodealliance/wasmtime-go" + "github.com/bytecodealliance/wasmtime-go/v5" "github.com/pkg/errors" "github.com/suborbital/e2core/foundation/scheduler" diff --git a/sat/engine2/runtime/pool.go b/sat/engine2/runtime/pool.go index 1a32ce17..6e6b73ba 100644 --- a/sat/engine2/runtime/pool.go +++ b/sat/engine2/runtime/pool.go @@ -1,9 +1,11 @@ package runtime import ( + "fmt" + "os" "sync" - "github.com/bytecodealliance/wasmtime-go" + "github.com/bytecodealliance/wasmtime-go/v5" "github.com/pkg/errors" "github.com/suborbital/e2core/foundation/scheduler" @@ -70,9 +72,27 @@ func (ip *InstancePool) UseInstance(ctx *scheduler.Ctx, instFunc func(*instance. // return it to the environment when finished inst := <-ip.availableInstances - defer func() { - ip.availableInstances <- inst - }() + reuseEnv := os.Getenv("SAT_REUSE_INSTANCE") + + // if instance reuse is disabled, trigger a new instance to be added + // if it is enabled, queue the instance to be re-added to the pool + if reuseEnv == "false" { + go func() { + if err := ip.AddInstance(); err != nil { + fmt.Println("FAILED TO ADDINSTANCE:" + err.Error()) + } + }() + + defer func() { + inst.Close() + inst = nil + }() + + } else { + defer func() { + ip.availableInstances <- inst + }() + } // generate a random identifier as a reference to the instance in use to // easily allow the Wasm module to reference itself when calling back over the FFI