관련지식
node.js, heap memory

메모리를 많이 사용할 경우 물리적인 메모리가 여유있음에도 불구하고 아래와 같이 ‘heap out of memory’가 발생할수가 있습니다.

  1. <--- Last few GCs --->
  2. [327:0x3fa68d0] 51611 ms: Mark-sweep 1333.6 (1393.5) -> 1333.6 (1362.5) MB, 277.5 / 0.0 ms (average mu = 0.595, current mu = 0.000) last resort GC in old space requested
  3. [327:0x3fa68d0] 51890 ms: Mark-sweep 1333.6 (1362.5) -> 1333.6 (1362.5) MB, 279.6 / 0.0 ms (average mu = 0.413, current mu = 0.000) last resort GC in old space requested
  4. <--- JS stacktrace --->
  5. ==== JS stack trace =========================================
  6. 0: ExitFrame [pc: 0xaf705ddbe1d]
  7. Security context: 0x31f93301e6e9 <JSObject>
  8. 1: parse_ws_xml_data [0x10e462be1629] [/nodejs/node_modules/xlsx/xlsx.js:~13114] [pc=0xaf7061c2a80](this=0x0041be803c41 <JSGlobal Object>,sdata=0x37c1d9382229 <Very long string[727548124]>,s=0x37c1d9382351 <Object map = 0x32c6fca8ae99>,opts=0x13aee7427651 <Object map = 0x32c6fca88921>,guess=0x37c1d9382329 <Object map = 0x32c6fca8ef91>,themes=0x13aee74276f...
  9. FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  10. 1: 0x8fa0c0 node::Abort() [node]
  11. 2: 0x8fa10c [node]
  12. 3: 0xb0026e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
  13. 4: 0xb004a4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
  14. 5: 0xef49b2 [node]

Java와 마찬가지로 VM에서 Heap메모리 최대한도가 정해져있기 때문입니다. 물론 가장 좋은것은 메모리를 적게 쓰도록 로직을 수정하는 것이지만, 그것이 어려울 경우 ‘—max-old-space-size’ 옵션을 주면 힙메모리 영역 한도를 키울수가 있습니다.

4GB 적용시)

  1. node --max-old-space-size=4096 app.js

만약 forever 패키지를 이용한 웹시스템에 적용하고 싶다면 아래와 같이 사용하면 됩니다.

8GB 적용시)

  1. forever start -c 'node --max-old-space-size=8192' app.js