diff --git a/apps/emqx_conf/i18n/emqx_conf_schema.conf b/apps/emqx_conf/i18n/emqx_conf_schema.conf
index fc33589ec..6123b313f 100644
--- a/apps/emqx_conf/i18n/emqx_conf_schema.conf
+++ b/apps/emqx_conf/i18n/emqx_conf_schema.conf
@@ -471,8 +471,8 @@ significant: later configuration files override the previous ones.
node_global_gc_interval {
desc {
- en: """Periodic garbage collection interval."""
- zh: """系统调优参数,设置节点运行多久强制进行一次全局垃圾回收。"""
+ en: """Periodic garbage collection interval. Set to disabled
if not enabled."""
+ zh: """系统调优参数,设置节点运行多久强制进行一次全局垃圾回收。禁用设置为 disabled
。"""
}
label {
en: "Global GC Interval"
diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl
index a68c11dc4..2080d32cb 100644
--- a/apps/emqx_conf/src/emqx_conf_schema.erl
+++ b/apps/emqx_conf/src/emqx_conf_schema.erl
@@ -468,7 +468,7 @@ fields("node") ->
)},
{"global_gc_interval",
sc(
- emqx_schema:duration(),
+ hoconsc:union([disabled, emqx_schema:duration()]),
#{
mapping => "emqx_machine.global_gc_interval",
default => "15m",
diff --git a/apps/emqx_conf/test/emqx_global_gc_SUITE.erl b/apps/emqx_conf/test/emqx_global_gc_SUITE.erl
index 121e12eba..9e4a5ffa6 100644
--- a/apps/emqx_conf/test/emqx_global_gc_SUITE.erl
+++ b/apps/emqx_conf/test/emqx_global_gc_SUITE.erl
@@ -29,4 +29,8 @@ t_run_gc(_) ->
ok = timer:sleep(1500),
{ok, MilliSecs} = emqx_global_gc:run(),
ct:print("Global GC: ~w(ms)~n", [MilliSecs]),
- emqx_global_gc:stop().
+ emqx_global_gc:stop(),
+ ok = emqx_config:put([node, global_gc_interval], disabled),
+ {ok, Pid} = emqx_global_gc:start_link(),
+ ?assertMatch(#{timer := undefined}, sys:get_state(Pid)),
+ ok.
diff --git a/apps/emqx_machine/src/emqx_global_gc.erl b/apps/emqx_machine/src/emqx_global_gc.erl
index 74825c321..a704d603c 100644
--- a/apps/emqx_machine/src/emqx_global_gc.erl
+++ b/apps/emqx_machine/src/emqx_global_gc.erl
@@ -82,10 +82,10 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
ensure_timer(State) ->
- case application:get_env(emqx_machine, global_gc_interval) of
- undefined ->
+ case application:get_env(emqx_machine, global_gc_interval, disabled) of
+ disabled ->
State;
- {ok, Interval} ->
+ Interval when is_integer(Interval) ->
TRef = emqx_misc:start_timer(Interval, run),
State#{timer := TRef}
end.
diff --git a/changes/v5.0.11-en.md b/changes/v5.0.11-en.md
index e53c5785e..ee00370fd 100644
--- a/changes/v5.0.11-en.md
+++ b/changes/v5.0.11-en.md
@@ -23,6 +23,8 @@
- Keep MQTT v5 User-Property pairs from bridge ingested MQTT messsages to bridge target [#9398](https://github.com/emqx/emqx/pull/9398).
+- Disable global garbage collection by `node.global_gc_interval = disabled` [#9418](https://github.com/emqx/emqx/pull/9418)。
+
## Bug fixes
- Fix `ssl.existingName` option of helm chart not working [#9307](https://github.com/emqx/emqx/issues/9307).
diff --git a/changes/v5.0.11-zh.md b/changes/v5.0.11-zh.md
index 3ea516dad..328c17467 100644
--- a/changes/v5.0.11-zh.md
+++ b/changes/v5.0.11-zh.md
@@ -21,6 +21,8 @@
- 为桥接收到的 MQTT v5 消息再转发时保留 User-Property 列表 [#9398](https://github.com/emqx/emqx/pull/9398)。
+- 通过 `node.global_gc_interval = disabled` 来禁用全局垃圾回收 [#9418](https://github.com/emqx/emqx/pull/9418)。
+
## 修复
- 修复 helm chart 的 `ssl.existingName` 选项不起作用 [#9307](https://github.com/emqx/emqx/issues/9307)。