Spark Streaming 运行时Java VM内存不足

报错如下:

17/07/10 00:50:18 INFO receiver.BlockGenerator: Pushed block input-0-1499619016600
17/07/10 00:50:19 INFO scheduler.JobScheduler: Added jobs for time 1499619019000 ms
17/07/10 00:50:20 INFO scheduler.JobScheduler: Added jobs for time 1499619020000 ms
17/07/10 00:50:21 INFO scheduler.JobScheduler: Added jobs for time 1499619021000 ms
17/07/10 00:50:22 INFO scheduler.JobScheduler: Added jobs for time 1499619022000 ms
17/07/10 00:50:23 INFO scheduler.JobScheduler: Added jobs for time 1499619023000 ms
17/07/10 00:50:26 INFO scheduler.JobScheduler: Added jobs for time 1499619024000 ms
17/07/10 00:50:26 INFO scheduler.JobScheduler: Added jobs for time 1499619025000 ms
17/07/10 00:50:26 INFO scheduler.JobScheduler: Added jobs for time 1499619026000 ms
17/07/10 00:50:28 INFO scheduler.JobScheduler: Added jobs for time 1499619027000 ms
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00007fbdc16f0000, 65536, 1) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 65536 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/spark-2.1.0-bin-hadoop2.6/hs_err_pid9397.log
#
# Compiler replay data is saved as:
# /home/spark-2.1.0-bin-hadoop2.6/replay_pid9397.log

解决办法:
1、检查 Swap 空间在设置 Swap 文件之前,有必要先检查一下系统里有没有既存的 Swap 文件。运行以下命令:

swapon -s

如果返回的信息搜索概要是空的,则表示 Swap 文件不存在。

2、检查文件系统在设置 Swap 文件之前,同样有必要检查一下文件系统,看看是否有足够的硬盘空间来设置 Swap 。运行以下命令:

df -hal

检查返回的信息,还剩余足够的硬盘空间即可。

3、创建并允许 Swap 文件下面使用 dd 命令来创建 Swap 文件。

dd if=/dev/zero of=/swapfile bs=1024 count=512k

参数解读:if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >bs=bytes:同时设置读入/输出的块大小为bytes个字节count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。

4、格式化并激活 Swap 文件上面已经创建好 Swap 文件,还需要格式化后才能使用。运行命令:

mkswap /swapfile

激活 Swap ,运行命令:

swapon /swapfile

以上步骤做完,再次运行命令:

swapon -s

你会发现返回的信息概要:

Filename Type Size Used Priority
/swapfile file 524284 0 -1
如果要机器重启的时候自动挂载 Swap ,那么还需要修改 fstab 配置。用 vim 打开 /etc/fstab 文件,在其最后添加如下一行:

/swapfile          swap            swap    defaults        0 0

最后,赋予 Swap 文件适当的权限:

chown root:root /swapfile 
chmod 0600 /swapfile

运行结果:
这里写图片描述

发布了203 篇原创文章 · 获赞 106 · 访问量 280万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章