fix: increase heartbeat time to avoid extreme MongoDB logging

Our MongoDB driver creates a new temporary connection, for every active
connection, to just do a single heartbeat test. There is configurable
delay between every heartbeat test. When the user has an EMQX cluster
with a MongoDB bridge (to a MongoDB replica set), there will be a lot of
connections. Furthermore, as MongoDB creates a log entry every time a
new connection is created, the log will be flooded with info about new
connection. One user have reported more than 1MB of log data in a 10
minute period.

This commit tries to fix this by increasing the default delay between
heartbeats. A better fix would be to change the MongoDB driver so that
it does not create a new connection just to do a heartbeat check, but
this is more complicated so we leave this to the future. We might also
swap out the current MongoDB driver to something better.

Fixes:
https://github.com/emqx/emqx/issues/9851
This commit is contained in:
Kjell Winblad 2023-03-13 14:21:51 +01:00
parent baf39fe080
commit 1cf01197bb
4 changed files with 11 additions and 3 deletions

View File

@ -177,8 +177,8 @@ The MongoDB default port 27017 is used if `[:Port]` is not specified."""
heartbeat_period {
desc {
en: "Controls when the driver checks the state of the MongoDB deployment. Specify the interval between checks, counted from the end of the previous check until the beginning of the next one."
zh: "控制驱动程序何时检查MongoDB部署的状态。指定检查的间隔时间从上一次检查结束到下一次检查开始计算。"
en: "Controls when the driver checks the state of the MongoDB deployment. Specify the interval between checks, counted from the end of the previous check until the beginning of the next one. If the number of connections is increased (which will happen, for example, if you increase the pool size), you may need to increase this period as well to avoid creating too many log entries in the MongoDB log file."
zh: "控制驱动程序何时检查MongoDB部署的状态。指定检查的间隔时间从上一次检查结束到下一次检查开始计算。如果连接数增加例如如果你增加池子的大小就会发生这种情况你可能也需要增加这个周期以避免在MongoDB日志文件中创建太多的日志条目。"
}
label {
en: "Heartbeat period"

View File

@ -106,7 +106,7 @@ fields(topology) ->
{socket_timeout_ms, duration("socket_timeout")},
{server_selection_timeout_ms, duration("server_selection_timeout")},
{wait_queue_timeout_ms, duration("wait_queue_timeout")},
{heartbeat_frequency_ms, duration("heartbeat_period")},
{heartbeat_frequency_ms, fun heartbeat_frequency_ms/1},
{min_heartbeat_frequency_ms, duration("min_heartbeat_period")}
].
@ -407,6 +407,12 @@ duration(Desc) ->
desc => ?DESC(Desc)
}.
heartbeat_frequency_ms(type) -> emqx_schema:duration_ms();
heartbeat_frequency_ms(desc) -> ?DESC("heartbeat_period");
heartbeat_frequency_ms(default) -> 200000;
heartbeat_frequency_ms(validator) -> [?MIN(1)];
heartbeat_frequency_ms(_) -> undefined.
max_overflow(type) -> non_neg_integer();
max_overflow(desc) -> ?DESC("max_overflow");
max_overflow(default) -> 0;

View File

@ -0,0 +1 @@
The default heartbeat period for MongoDB has been increased to reduce the risk of too excessive logging to the MongoDB log file.

View File

@ -0,0 +1 @@
增加了MongoDB的默认心跳周期以减少对MongoDB日志文件的过多记录的风险。