From 22a27700199ffde6cd959c6b11a20eec325ec59c Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Dec 2023 22:19:35 +0800 Subject: [PATCH] [add] YAO_RUNTIME_TIMEOUT Environment Variable --- config/types.go | 3 +++ runtime/runtime.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/types.go b/config/types.go index 3b3f125e..6e2cccef 100644 --- a/config/types.go +++ b/config/types.go @@ -52,8 +52,11 @@ type Session struct { // Runtime Config type Runtime struct { + Mode string `json:"mode,omitempty" env:"YAO_RUNTIME_MODE" envDefault:"normal"` // the mode of the runtime, the default value is "normal" and the other value is "performance". "performance" mode need more memory but will run faster MinSize int `json:"minSize,omitempty" env:"YAO_RUNTIME_MIN" envDefault:"10"` // the number of V8 VM when runtime start. max value is 100, the default value is 2 MaxSize int `json:"maxSize,omitempty" env:"YAO_RUNTIME_MAX" envDefault:"100"` // the maximum of V8 VM should be smaller than minSize, the default value is 10 + DefaultTimeout int `json:"defaultTimeout,omitempty" env:"YAO_RUNTIME_TIMEOUT" envDefault:"200"` // the default timeout for the script, the default value is 200ms + ContextTimeout int `json:"contextTimeout,omitempty" env:"YAO_RUNTIME_CONTEXT_TIMEOUT" envDefault:"200"` // the default timeout for the context, the default value is 200ms HeapSizeLimit uint64 `json:"heapSizeLimit,omitempty" env:"YAO_RUNTIME_HEAP_LIMIT" envDefault:"1518338048"` // the isolate heap size limit should be smaller than 1.5G, and the default value is 1518338048 (1.5G) HeapSizeRelease uint64 `json:"heapSizeRelease,omitempty" env:"YAO_RUNTIME_HEAP_RELEASE" envDefault:"52428800"` // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M) HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty" env:"YAO_RUNTIME_HEAP_AVAILABLE" envDefault:"524288000"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M) diff --git a/runtime/runtime.go b/runtime/runtime.go index 4988e40e..35b64295 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -16,6 +16,9 @@ func Start(cfg config.Config) error { HeapSizeRelease: cfg.Runtime.HeapSizeRelease, Precompile: cfg.Runtime.Precompile, DataRoot: cfg.DataRoot, + Mode: cfg.Runtime.Mode, + DefaultTimeout: cfg.Runtime.DefaultTimeout, + ContextTimeout: cfg.Runtime.ContextTimeout, } err := v8.Start(option)