Lua5.4 GC
· 阅读需 3 分钟
http://www.lua.org/manual/5.4/manual.html#2.5.2
lua 5.4 分代GC, 执行全量gc卡顿问题 https://blog.codingnow.com/2018/10/lua_gc.html
云风游戏服务器应用GC方案,切换GC模式时卡顿 http://lua-users.org/lists/lua-l/2020-12/msg00175.html
建议agent服务采用增量GC, 控制内存。常驻唯一服务采用分代GC.
collectgarbage
- 切换增量GC:
collectgarbage("incremental", pause, stepmul, stepsize)
- pause 间歇率,垃圾收集器间歇率控制着收集器需要在开启新的循环前要等待多久。 增大这个值会减少收集器的积极性。 当这个值比 100 小的时候,收集器在开启新的循环前不会有等待。 设置这个值为 200 就会让收集器等到总内存使用量达到 之前的两倍时才开始新的循环。默认值是200,最大值1000
- stepmul 垃圾收集器步进倍率控制着收集器运作速度相对于内存分配速度的倍率。 增大这个值不仅会让收集器更加积极,还会增加每个增量步骤的长度。 不要把这个值设得小于 100 , 那样的话收集器就工作的太慢了以至于永远都干不完一个循环。 默认值是 100.
- stepsize 控制申请多少内存后触发一个增量GC步骤,
This parameter is logarithmic:A value of n means the interpreter will allocate 2n bytes between steps and perform equivalent work during the step. A large value (e.g., 60) makes the collector a stop-the-world (non-incremental) collector. The default value is 13, which means steps of approximately 8 Kbytes.
- 切换分代GC:
collectgarbage("generational", minor_multiplier, major_multiplier)
- minor_multiplier 控制年轻对象收集倍率,对于一个倍率
X
, 新的minor collection
将会在内存使用比上次major collection
后增长X%
时完成. 默认值是20,最大值200 - major_multiplier 控制年老对象收集倍率,对于一个倍率
X
, 新的major collection
将会在内存使用比上次major collection
后增长X%
时完成. 默认值是100,最大值1000
- minor_multiplier 控制年轻对象收集倍率,对于一个倍率