[Jenkins] java.lang.OutOfMemoryError: Java heap space

2023. 7. 4. 03:30ใ†๊ฐœ๋… ์ •๋ฆฌ ์ž‘์—…์‹ค/๋ฌธ์ œ ์ •๋ฆฌ

728x90
๋ฐ˜์‘ํ˜•

๋ฐ˜์‘ํ˜•

 

 

 

๋ฐฐํฌ ์ž๋™ํ™”์™€ ์ง€์†์  ์ธ๋„:๋„์ปค์™€ ์  ํ‚จ์Šค ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋กœ ๋งŒ๋“œ๋Š”

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

๐Ÿ‘ท‍โ™‚๏ธ ์ž‘์—… ์ค‘์ธ ๋‚ด์šฉ

ํ˜„์žฌ ์ฃผ๋‹ˆ๋Š” ์  ํ‚จ์Šค๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ ์ค‘์ธ๋ฐ, ์ด ์ „์—๋Š” ๋ฌธ์ œ ์—†์ด ์ž˜ ๋˜์—ˆ๋‹ค๊ฐ€ ์–ด๋Š๋‚  ๋ถ€ํ„ด๊ฐ€ 

INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 16.330s
INFO: Final Memory: 24M/87M
INFO: ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // script
Post stage
[Pipeline] discordSend
Sending notification to Discord.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (SONARQUBE_QUALITY_GATE)
Stage "SONARQUBE_QUALITY_GATE" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (๊ฐœ๋ฐœ ํ™˜๊ฒฝ Application ์„œ๋ฒ„์— File ์ „๋‹ฌ ๋ฐ ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ)
Stage "๊ฐœ๋ฐœ ํ™˜๊ฒฝ Application ์„œ๋ฒ„์— File ์ „๋‹ฌ ๋ฐ ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (๊ฐœ๋ฐœ ํ™˜๊ฒฝ Docker Image ์ƒ์„ฑ ๋ฐ Backup ์ž‘์—…)
Stage "๊ฐœ๋ฐœ ํ™˜๊ฒฝ Docker Image ์ƒ์„ฑ ๋ฐ Backup ์ž‘์—…" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (๊ฐœ๋ฐœ ํ™˜๊ฒฝ Docker ๊ด€๋ จ ์ž‘์—…)
Stage "๊ฐœ๋ฐœ ํ™˜๊ฒฝ Docker ๊ด€๋ จ ์ž‘์—…" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (์šด์˜ ํ™˜๊ฒฝ WAS ์„œ๋ฒ„์— File ์ „๋‹ฌ ๋ฐ ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ)
Stage "์šด์˜ ํ™˜๊ฒฝ WAS ์„œ๋ฒ„์— File ์ „๋‹ฌ ๋ฐ ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (์šด์˜ ํ™˜๊ฒฝ Docker Image ์ƒ์„ฑ ๋ฐ Backup ์ž‘์—…)
Stage "์šด์˜ ํ™˜๊ฒฝ Docker Image ์ƒ์„ฑ ๋ฐ Backup ์ž‘์—…" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (์šด์˜ ํ™˜๊ฒฝ Docker ๊ด€๋ จ ์ž‘์—…)
Stage "์šด์˜ ํ™˜๊ฒฝ Docker ๊ด€๋ จ ์ž‘์—…" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Jenkins CI/CD ์ž‘์—… ์™„๋ฃŒ)
Stage "Jenkins CI/CD ์ž‘์—… ์™„๋ฃŒ" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.OutOfMemoryError: Java heap space
[Gitea] Notifying branch build status: FAILURE There was a failure building this commit
[Gitea] Notified
Finished: FAILURE


์œ„์™€ ๊ฐ™์ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด์„œ Sonar Qube์˜ QUALITY_GATE ๋‹จ๊ณ„๋ฅผ ๋„˜์–ด๊ฐ€์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.

 

728x90

 

๐Ÿค” ์›์ธ ๋ถ„์„


์ฃผ๋‹ˆ๋Š” ์  ํ‚จ์Šค์˜ ์œ„ Error Log ์ค‘ java.lang.OutOfMemoryError: Java heap space ์ด ๋ถ€๋ถ„์— ์ฃผ๋ชฉํ•˜์˜€๊ณ ,
์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด ํ•ด๊ฒฐ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.


์œ„์˜ ๋ฌธ์ œ๋Š” ๊ฒฐ๊ตญ ์  ํ‚จ์Šค ๋ฐฐํฌ ์ค‘ JAVA (์  ํ‚จ์Šค๋Š” JAVA ๊ธฐ๋ฐ˜ Application) ๊ฐ€์ƒ ๋จธ์‹  ์ฆ‰, JVM์—์„œ Heap Memory๊ฐ€ ๋ถ€์กฑํ•˜๋‹ค๊ณ  ์•Œ๋ ค์ฃผ๋Š” ๊ฑฐ์—์š”.


๊ทธ ์ „์— Jenkins Container ์ž์› ์‚ฌ์šฉ๋Ÿ‰์„ ์กฐ์‚ฌํ•ด ๋ณด์•˜์–ด์š”.


docker stats {Container Name}

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
CPU % : CPU ์‚ฌ์šฉ๋ฅ 
MEM USAGE / LIMIT : Container Memory ์‚ฌ์šฉ๋Ÿ‰(MB) / Container ์‚ฌ์šฉ ๊ฐ€๋Šฅ Memory ์ œํ•œ ์šฉ๋Ÿ‰
MEM % : Container Memory ์‚ฌ์šฉ๋Ÿ‰
NET I/O: Network Input, Output
BLOCK I/O: Network ์ฐจ๋‹จ Input, Output
PIDS : Process ID


์ตœ์ดˆ ์  ํ‚จ์Šค ์ปจํ…Œ์ด๋„ˆ ๋ฉ”๋ชจ๋ฆฌ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, ๋งค์šฐ ์ถฉ๊ฒฉ์ ์ด์˜€์–ด์š”.

Memory ์‚ฌ์šฉ๋Ÿ‰์ด ๋ฌด๋ ค 243%๋กœ ๊ณผ๋ถ€ํ•˜๊ฐ€ ๊ฑธ๋ฆฌ๊ณ  ์žˆ๋‹ค๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์–ด์š”.

๋ฐฐํฌ ๋‹จ๊ณ„์™€ ํ•  ๊ฒƒ๋“ค์ด ๋งŽ์•„์ง€๋‹ˆ ์  ํ‚จ์Šค๊ฐ€ ๋ฒ„๊ฑฐ์›Œ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋Š๋‚„ ์ˆ˜ ์žˆ์—ˆ์–ด์š”. 

๋จผ์ € Container์— ์ž์› ์‚ฌ์šฉ ์ œํ•œ์„ ๋Š˜๋ ค์ฃผ๊ณ , Heap Size๋ฅผ ๋Š˜๋ ค์ค˜์•ผ ๊ฒ ์–ด์š”.





๐Ÿป ๋ฌธ์ œ ํ•ด๊ฒฐ!

vim giggal-master-jenkins.sh


์ฃผ๋‹ˆ๋Š” ์œ„์™€ ๊ฐ™์ด Docker ๊ธฐ๋™ ๋ช…๋ น์–ด๋ฅผ Shell Script๋กœ ๋งŒ๋“ค์–ด์„œ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ, 2๋ฒˆ์งธ ์ค„๊ณผ ๊ฐ™์ด Memory ์ œํ•œ ํฌ๊ธฐ๋ฅผ 2GB๋กœ ๋Š˜๋ ค์ฃผ๊ณ , ๋งŒ์•ฝ Host Server์˜ Memory๊ฐ€ ๋ถ€์กฑํ•˜๊ฒŒ ๋˜๋ฉด 1GB๋กœ ์ œํ•œ๋  ์ˆ˜ ์žˆ๋„๋ก ๋ช…๋ น์–ด๋ฅผ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.


Container๋ฅผ ์‚ญ์ œํ•˜๊ณ , ์œ„ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ†ตํ•ด ์žฌ ๊ธฐ๋™ํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, ์œ„์™€ ๊ฐ™์€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋˜์—ˆ์–ด์š”.

์ด๋Š” ์ปค๋„ ์„ค์ • ๋ฌธ์ œ๋กœ swap์— ๋Œ€ํ•œ ์ œํ•œ์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๋‚ด์šฉ์ด์—์š”.
์ด๋Ÿด ๋•Œ๋Š” swap limit capablities๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ˆ˜์ •ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

vim /etc/default/grub ๋ณ€๊ฒฝ ์ „


์ฐธ๊ณ ๋กœ ์ฃผ๋‹ˆ๋Š” Ubuntu 22.04 LTS Linux๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์š”.

vim /etc/default/grub ๋ณ€๊ฒฝ ํ›„

 

update-grub && reboot


๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•œ ๋‚ด์šฉ์ด ์ธ์‹๋  ์ˆ˜ ์žˆ๊ฒŒ Update ๋ช…๋ น์–ด๋ฅผ ๋‚ ๋ ค์ค๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ , ์„œ๋ฒ„ ์ž์ฒด๋ฅผ ์žฌ๋ถ€ํŒ… ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.



์œ„์™€ ๊ฐ™์ด Memory ์„ค์ • ๋ถ€๋ถ„์ด ์ธ์‹๋˜๋ฉด์„œ Jenkins Container ๊ธฐ๋™ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋™์ž‘๋œ ๊ฑธ ์•Œ ์ˆ˜ ์žˆ์–ด์š”.

๋งŒ์•ฝ ์ด๋ ‡๊ฒŒ ์žฌ๋ถ€ํŒ…๊นŒ์ง€ ํ–ˆ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ , Memory ์‚ฌ์šฉ๋Ÿ‰์ด ๋Š˜์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค๋ฉด
Docker Deamon์„ ์žฌ ๊ธฐ๋™ํ•ด์ฃผ๋ฉด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์–ด์š”.

systemctl restart docker



docker stats {Container Name}


์ด๋ ‡๊ฒŒ Memory๊ฐ€ ๋Š˜์–ด๋‚œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


์ด๋ฒˆ์— ๋‹ค์‹œ ์  ํ‚จ์Šค ๊ธฐ๋™ ์Šคํฌ๋ฆฝํŠธ์— ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ๋ณผ๊ฑฐ์—์š”.

vim giggal-master-jenkins.sh


๋ฐ”๋กœ 3๋ฒˆ์งธ ์ค„๊ณผ ๊ฐ™์ด Container์˜ Heap Size๋ฅผ ์ง€์ •ํ•ด ์ฃผ์–ด ๊ธฐ๋™ ์‹œ์ผœ ๋ณด๋ ค๊ณ  ํ•ด์š”.

์ด๋ ‡๊ฒŒ ํ•˜๊ณ  Container๋ฅผ ์‚ญ์ œํ•œ ๋’ค ๋‹ค์‹œ ์žฌ ๊ธฐ๋™ํ•ด ์ค„๊ฒŒ์š”.

docker stop {container ID} && docker rm {container ID}

 

 

docker ps -a


๊ธฐ๋™์ด ์ž˜ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



๋‹ค์‹œ ์  ํ‚จ์Šค ์ž‘์—…์„ ์‹œ์ž‘ํ•ด ๋ณด์•˜์–ด์š”.



์ด๋ ‡๊ฒŒ ์ž˜ ์ฒ˜๋ฆฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

 

๋ฐฐํฌ ์ž๋™ํ™”์™€ ์ง€์†์  ์ธ๋„:๋„์ปค์™€ ์  ํ‚จ์Šค ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋กœ ๋งŒ๋“œ๋Š”

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•