Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine2)!: add experimental no-module-reuse option #366

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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