[Linux] 編譯 Google Protocol Buffer 時不要用 make -j 平行編譯

[Linux] 編譯 Google Protocol Buffer 時不要用 make -j 平行編譯

前一陣子幫專案用 make -j 的方式,執行平行編譯,加快編譯的速度,

不過最近在加上 Google Protocol Buffer 的編譯之後,

卻發現常常在編譯到 Google Protocol Buffer 時,編譯速度突然變得非常的慢,

甚至會有機器好像整台停下來的狀況…

 

研究了一下,原來是記憶體用量的問題…

使用 make -j 時,只要有 make 的動作,就會再多跑出一個 process 來編譯,

以 Google Protocol Buffer 來說,似乎它裡面會去 make 非常多的東西,

導致有非常多的 process 都在執行 make,把記憶體都吃光光,

最後記憶體沒了之後,就開始吃 SWAP,自然電腦速度就會變得超慢的了…

 

下面是用 make -j 編譯 Google Protocol Buffer,觀察記憶體的使用量~

可以看到原本還有剩 5GB,後來越來越少,最後只剩一百多 MB:

Fri Feb 17 17:23:33 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       2.6G       5.0G       2.5M         0B       2.1G
-/+ buffers/cache:       567M       7.1G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:35 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       2.8G       4.9G       2.5M         0B       2.1G
-/+ buffers/cache:       725M       6.9G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:38 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       3.5G       4.1G       2.5M         0B       2.1G
-/+ buffers/cache:       1.4G       6.2G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:40 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       4.1G       3.5G       2.5M         0B       2.1G
-/+ buffers/cache:       2.0G       5.6G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:43 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       4.7G       3.0G       2.5M         0B       2.1G
-/+ buffers/cache:       2.6G       5.0G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:45 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       4.8G       2.9G       2.5M         0B       2.1G
-/+ buffers/cache:       2.7G       4.9G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:48 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       5.1G       2.5G       2.5M         0B       2.1G
-/+ buffers/cache:       3.1G       4.6G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:51 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       5.3G       2.3G       2.5M         0B       2.1G
-/+ buffers/cache:       3.3G       4.4G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:54 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       5.5G       2.1G       2.5M         0B       2.1G
-/+ buffers/cache:       3.5G       4.2G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:23:56 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       5.8G       1.9G       2.5M         0B       2.1G
-/+ buffers/cache:       3.7G       3.9G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:00 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       6.1G       1.5G       2.5M         0B       2.1G
-/+ buffers/cache:       4.0G       3.6G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:03 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       6.3G       1.4G       2.5M         0B       2.1G
-/+ buffers/cache:       4.2G       3.4G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:06 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       6.6G       1.0G       2.5M         0B       2.1G
-/+ buffers/cache:       4.5G       3.1G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:09 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.0G       703M       2.5M         0B       2.1G
-/+ buffers/cache:       4.9G       2.8G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:12 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.2G       462M       2.5M         0B       2.1G
-/+ buffers/cache:       5.1G       2.5G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:16 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.5G       158M       2.5M         0B       1.8G
-/+ buffers/cache:       5.7G       2.0G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:21 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.5G       132M       2.5M         0B       1.4G
-/+ buffers/cache:       6.1G       1.5G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:25 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.5G       110M       2.5M         0B       914M
-/+ buffers/cache:       6.6G       1.0G
Swap:         7.9G       896M       7.0G
Fri Feb 17 17:24:28 CST 2017
total       used       free     shared    buffers     cached
Mem:          7.6G       7.5G       101M       2.5M         0B       554M
-/+ buffers/cache:       7.0G       655M
Swap:         7.9G       896M       7.0G

 

後來將編譯 Google Protocol Buffer 的部分時,

指定成 make -j 1 (也就是不多開新的 process),就沒有這個問題了~

(本頁面已被瀏覽過 288 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料