Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion sat/engine2/runtime/instance/instance.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
28 changes: 24 additions & 4 deletions sat/engine2/runtime/pool.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down