lolly/internal/lua/config.go
xfy 686b8c3239 refactor(lua): 调整配置字段顺序将协程池参数集中
将 CoroutinePoolWarmup 字段移至 CoroutineStackSize 后,
使协程相关配置字段集中在一起,便于理解和维护。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:53:12 +08:00

42 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package lua 提供 Lua 脚本嵌入能力
// 采用 Server 级单 LState + 请求级临时协程架构
package lua
import (
"time"
)
// Config Lua 引擎配置
type Config struct {
MaxConcurrentCoroutines int
CoroutineTimeout time.Duration
CodeCacheSize int
CodeCacheTTL time.Duration
MaxExecutionTime time.Duration
CoroutineStackSize int // 协程栈大小默认64最大256
CoroutinePoolWarmup int // 协程池预热数量,启动时预创建
EnableFileWatch bool // 1
EnableOSLib bool // 1
EnableIOLib bool // 1
EnableLoadLib bool // 1
MinimizeStackMemory bool // 启用栈内存自动收缩以减少内存占用
}
// DefaultConfig 返回默认配置
func DefaultConfig() *Config {
return &Config{
MaxConcurrentCoroutines: 1000,
CoroutineTimeout: 30 * time.Second,
CodeCacheSize: 1000,
CodeCacheTTL: time.Hour,
EnableFileWatch: true,
MaxExecutionTime: 30 * time.Second,
EnableOSLib: false,
EnableIOLib: false,
EnableLoadLib: false,
CoroutineStackSize: 64, // 优化:较小的栈减少内存分配
MinimizeStackMemory: true,
CoroutinePoolWarmup: 4, // 预热4个协程结构
}
}