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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章