kibana 的oom问题 JavaScript heap out of memory
创始人
2025-05-31 15:55:26
0

bug kibana docker 自动重启 导致业务访问显示 kibana not yet

排查

因为 es和 logstash 都正常运行。 green 节点green 查看 kibana 日志


<--- Last few GCs --->[6:0x25fdcc0]   370913 ms: Mark-sweep 854.6 (1060.6) -> 854.5 (1028.6) MB, 143.5 / 0.0 ms  (average mu = 0.862, current mu = 0.000) last resort GC in old space requested
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
[6:0x25fdcc0]   371055 ms: Mark-sweep 854.5 (1028.6) -> 854.5 (1028.1) MB, 142.6 / 0.0 ms  (average mu = 0.757, current mu = 0.000) last resort GC in old space requested<--- JS stacktrace --->==== JS stack trace =========================================Security context: 0x2c5f0f01e6e1 0: builtin exit frame: parse(this=0x2c5f0f011a19 ,0x00e497472769 ,0x2c5f0f011a19 )1: deserialize [0x18158f1ac1f9] [/usr/share/kibana/node_modules/elasticsearch/src/lib/serializers/json.js:~42] [pc=0x395cec7c852a](this=0x243dcfe95eb1 ,str=0x00e497472769  

发现是 kibana前端 js 报的内存 oom 异常,通过网上资料发现node.js 的默认内存大小为1.4g ,那么问题就定位到修改node 的内存限制。

修改node 的内存限制

docker 实际启动路径 /usr/share/kibana/bin/kibana
查看kibana 执行文件


#!/bin/sh
SCRIPT=$0# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; dols=$(ls -ld "$SCRIPT")# Drop everything prior to ->link=$(expr "$ls" : '.*-> \(.*\)$')if expr "$link" : '/.*' > /dev/null; thenSCRIPT="$link"elseSCRIPT=$(dirname "$SCRIPT")/"$link"fi
doneDIR="$(dirname "${SCRIPT}")/.."
NODE="${DIR}/node/bin/node"
test -x "$NODE"
if [ ! -x "$NODE" ]; thenecho "unable to find usable node.js executable."exit 1
fiNODE_ENV=production exec "${NODE}" --no-warnings --max-http-header-size=65536 $NODE_OPTIONS "${DIR}/src/cli" ${@}添加内存空间的环境变量 Solution
NODE_ENV=production exec "${NODE}" --no-warnings --max-http-header-size=65536 $NODE_OPTIONS --max-old-space-size=12288 "${DIR}/src/cli" ${@}

解决办法:

在 kibana 启动文件 添加内存空间的环境变量 Solution
添加 $NODE_OPTIONS --max-old-space-size=12288

拓展 关于 node.JS NODE_OPTIONS --max-old-space-size 参数

参照官方文档的解释:
https://nodejs.org/api/cli.html#cli_node_options_options
V8 has its own set of CLI options. Any V8 CLI option that is provided to node will be passed on to V8 to handle. V8’s options have no stability guarantee. The V8 team themselves don’t consider them to be part of their formal API, and reserve the right to change them at any time. Likewise, they are not covered by the Node.js stability guarantees. Many of the V8 options are of interest only to V8 developers. Despite this, there is a small set of V8 options that are widely applicable to Node.js, and they are documented here:
–max-old-space-size=SIZE (in megabytes)
Sets the max memory size of V8’s old memory section. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
On a machine with 2 GiB of memory, consider setting this to 1536 (1.5 GiB) to leave some memory for other uses and avoid swapping.
$ node --max-old-space-size=1536 index.js

翻译提炼为:
Old space是 V8 托管(也称为垃圾收集)堆(即 JavaScript 对象所在的位置)中最大和最可配置的部分,而 --max-old-space-size 标志控制其最大大小。 随着内存消耗接近极限,V8 将花费更多时间在垃圾收集上,以释放未使用的内存。
如果堆内存消耗(即 GC 无法释放的活动对象)超过限制,V8 将使您的进程崩溃(因为缺乏替代方案),因此您不想将其设置得太低。 当然,如果您将其设置得太高,那么 V8 将允许的额外堆使用可能会导致您的整个系统内存不足(并且由于缺乏替代方案而交换或终止随机进程)。
总之,在具有 2GB 内存的机器上,我可能会将 --max-old-space-size 设置为大约 1.5GB 以留出一些内存用于其他用途并避免交换。

2G的内存机器,单独运行 node 进程,设置为1.5GB 这里1536 = 1.5GB 。所以 --max-old-space-size 的单位是 MB

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
有效的括号 一、题目 给定一个只包括 '(',')','{','}'...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
【Ctfer训练计划】——(三... 作者名:Demo不是emo  主页面链接:主页传送门 创作初心ÿ...