Files
go-admin/config/settings.yml
T
zhangwenjian 1bc2e22833 fix🐛: give the config templates the defaults a deployment actually needs
Two settings that decide whether a deployment survives load, neither of which
appeared in any template.

The connection pool. Left unset, Go's defaults apply, and MaxIdleConns is 2:
under load almost every request opens a TCP connection and closes it again,
local ports run out, and the process answers "can't assign requested address"
to everything. Not slower - unavailable. A sweep against MySQL collapsed to
zero successful responses at 64 concurrent requests without these, and served
13,846 req/s with no errors once they were set.

The queue buffer. poolSize is the point at which messages start being dropped,
not a tuning knob: a full queue discards the message and returns an error
rather than blocking, and each stream has one consumer goroutine writing to the
database. At the previous default of 100 a load test lost over 60% of them; at
1000, none. Login and operation logs travel this queue, so what gets lost is
audit data - though only when logger.enableddb is on.

Both carry the reasoning in the file, because the failure mode of each is
invisible until it happens in production.
2026-08-28 19:42:38 +08:00

94 lines
4.0 KiB
YAML
Raw 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.
settings:
application:
# dev开发环境 test测试环境 prod线上环境
mode: dev
# 服务器ip,默认使用 0.0.0.0
host: 0.0.0.0
# 服务名称
name: testApp
# 端口号
port: 8000 # 服务端口号
readtimeout: 1
writertimeout: 2
# 数据权限功能开关
enabledp: false
logger:
# 日志存放路径
path: temp/logs
# 日志输出,file:文件,default:命令行,其他:命令行
stdout: '' #控制台日志,启用后,不输出到文件
# 日志等级, trace, debug, info, warn, error, fatal
level: trace
# 数据库日志开关
enableddb: false
jwt:
# token 密钥,生产环境时及的修改
secret: go-admin
# token 过期时间 单位:秒
timeout: 3600
database:
# 数据库类型 mysql, sqlite3, postgres, sqlserver
# sqlserver: sqlserver://用户名:密码@地址?database=数据库名
driver: mysql
# 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# 连接池。不配置这几项时走 Go 的默认值,其中 MaxIdleConns 默认只有 2
# 高并发下几乎每个请求都要新建 TCP 连接、用完立刻关闭,本机端口很快耗尽,
# 表现为 "can't assign requested address" 且请求全部失败——不是变慢,是不可用。
#
# maxOpenConns 是单个实例的连接上限,多实例部署时总连接数是它乘以实例数,
# 需要小于数据库的 max_connectionsMySQL 默认 151)。
# connMaxLifeTime 单位为秒,应小于数据库的 wait_timeoutMySQL 默认 28800),
# 否则会复用到已被服务端关闭的连接。
maxIdleConns: 20
maxOpenConns: 100
connMaxLifeTime: 3600
# databases:
# 'locaohost:8000':
# driver: mysql
# # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
# registers:
# - sources:
# - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms
gen:
# 代码生成读取的数据库名称
dbname: dbname
# 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径
frontpath: ../go-admin-ui/src
extend: # 扩展项使用说明
demo:
name: data
# rateLimit 全局入站限流。不配置时为 200 QPS,与此前写死在
# common/middleware/sentinel.go 里的值一致,升级不会改变行为。
# 填 0 关闭限流——部署在自带限流的网关后面时用得上。
# 超出阈值的请求返回 HTTP 429(旧版本返回 200,只在 body 里写 code:500
# 会被负载均衡、监控和压测统计成成功)。
rateLimit:
inboundQPS: 200
cache:
# redis:
# addr: 127.0.0.1:6379
# password: xxxxxx
# db: 2
# key存在即可
memory: ''
queue:
memory:
# poolSize 是队列的缓冲长度,不是并发度。队列满时 Append 会丢弃该消息并
# 返回错误,而不是阻塞等待,所以这个值实际是「开始丢消息的临界点」。
#
# 每个 stream 只有一个消费 goroutine,而登录日志、操作日志的消费要写数据库,
# 吞吐受限于单条写入耗时。突发流量高于消费速度时,缓冲区是唯一的缓解手段。
# 压测中默认的 100 丢弃率超过 60%,1000 为 0。
#
# 仅在 logger.enableddb 为 true 时才会真正入队。
poolSize: 1000
# redis:
# addr: 127.0.0.1:6379
# password: xxxxxx
# group: go-admin # 消费组,同一应用的多个实例必须用同一个值
# key_prefix: go-admin # 加在 stream key 前面,多个应用共用一个 redis 时用于隔离
# max_attempts: 5 # 消息投递失败的最大重试次数
locker:
redis: