当前位置:   article > 正文

node 内存溢出_<--- last few gcs ---> [4712:000001e62c0a4580] 626

<--- last few gcs ---> [4712:000001e62c0a4580] 626912 ms: mark-sweep (reduce
  1. <--- Last few GCs --->
  2. [24332:000001ED3A02F230] 23391 ms: Mark-sweep (reduce) 8032.8 (8041.3) -> 8032.5 (8036.3) MB, 5119.3 / 0.0 ms (+ 5.5 ms in 2 steps since start of marking, biggest step 5.5 ms, walltime since start of marking 5323 ms) (average mu = 0.270, current mu = [24332:000001ED3A02F230] 28990 ms: Mark-sweep (reduce) 8192.5 (8196.3) -> 8192.5 (8196.0) MB, 5520.6 / 0.0 ms (average mu = 0.142, current mu = 0.014) allocation failure scavenge might not succeed
  3. <--- JS stacktrace --->
  4. FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
  5. 1: 00007FF7BE2E013F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112495
  6. 2: 00007FF7BE26F396 DSA_meth_get_flags+65526
  7. 3: 00007FF7BE27024D node::OnFatalError+301
  8. 4: 00007FF7BEBA19EE v8::Isolate::ReportExternalAllocationLimitReached+94
  9. 5: 00007FF7BEB8BECD v8::SharedArrayBuffer::Externalize+781
  10. 6: 00007FF7BEA2F61C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
  11. 7: 00007FF7BEA2C754 v8::internal::Heap::CollectGarbage+4244
  12. 8: 00007FF7BEA2A0D0 v8::internal::Heap::AllocateExternalBackingStore+2000
  13. 9: 00007FF7BEA47D40 v8::internal::FreeListManyCached::Reset+1408
  14. 10: 00007FF7BEA483F5 v8::internal::Factory::AllocateRaw+37
  15. 11: 00007FF7BEA5A0EE v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray+46
  16. 12: 00007FF7BEA5CD4A v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller+74
  17. 13: 00007FF7BEA5CC6D v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+77
  18. 14: 00007FF7BE9060F3 v8::internal::FeedbackNexus::ic_state+61859
  19. 15: 00007FF7BE92D867 v8::Message::GetIsolate+83559
  20. 16: 00007FF7BE92CACF v8::Message::GetIsolate+80079
  21. 17: 00007FF7BE880F40 v8::internal::JSArray::SetLength+240
  22. 18: 00007FF7BE8FF629 v8::internal::FeedbackNexus::ic_state+34521
  23. 19: 00007FF7BE791A85 v8::internal::CompilationCache::IsEnabledScriptAndEval+27701
  24. 20: 00007FF7BEC2F3E1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
  25. 21: 000001ED3BDF1521

 

  1. // 全局变量
  2. let total = []
  3. //内存溢出
  4. const toolsMemory = async (req, res) => {
  5. const { uid } = req.body
  6. function getMemory(n = 1) {
  7. let memory = process.memoryUsage()
  8. console.log(`rss:${(memory.rss / 1024 / 1024).toFixed(1)}MB`)
  9. console.log(`external:${(memory.external / 1024 / 1024).toFixed(1)}MB`)
  10. console.log(
  11. `arrayBuffers:${(memory.arrayBuffers / 1024 / 1024).toFixed(1)}MB`
  12. )
  13. console.log(`申请到内存:${(memory.heapTotal / 1024 / 1024).toFixed(1)}MB`)
  14. console.log(`已使用内存:${(memory.heapUsed / 1024 / 1024).toFixed(1)}MB`)
  15. let totalmem = os.totalmem() // 以整数形式返回系统内存总量(以字节为单位B)
  16. let freemem = os.freemem() // 以整数形式返回空闲的系统内存量(以字节为单位B)。
  17. console.log(
  18. `系统总内存:${(totalmem / 1024 / 1024).toFixed(1)}\n系统空闲内存:${(
  19. freemem /
  20. 1024 /
  21. 1024
  22. ).toFixed(1)}`
  23. )
  24. console.log(`--------------------循环了${n}次`)
  25. return `
  26. rss:${(memory.rss / 1024 / 1024).toFixed(1)}MB
  27. external:${(memory.external / 1024 / 1024).toFixed(1)}MB
  28. arrayBuffers:${(memory.arrayBuffers / 1024 / 1024).toFixed(1)}MB
  29. 申请到内存:${(memory.heapTotal / 1024 / 1024).toFixed(1)}MB
  30. 已使用内存:${(memory.heapUsed / 1024 / 1024).toFixed(1)}MB
  31. 系统总内存:${(totalmem / 1024 / 1024).toFixed(1)}\n系统空闲内存:${(
  32. freemem /
  33. 1024 /
  34. 1024
  35. ).toFixed(1)}
  36. `
  37. }
  38. // 每次都会接受一个大数组
  39. // function useMem() {
  40. // let size = 20 * 1024 * 1024
  41. // let arr = new Array(size)
  42. // return arr
  43. // }
  44. // for (let j = 0; j < 100; j++) {
  45. // getMemory(j + 1)
  46. // total.push(useMem())
  47. // }
  48. // console.log('success')
  49. let info = getMemory()
  50. res.send({
  51. code: 200,
  52. data: {
  53. uid,
  54. info,
  55. },
  56. message: '成功',
  57. })
  58. }

解决方案:

  1. "scripts": {
  2. "dev1": "cross-env PORT=85 NODE_ENV=development NODE_OPTIONS=--max_old_space_size=8096 nodemon --inspect --max_old_space_size=8096 app.js",
  3. "dev11": "cross-env PORT=85 NODE_OPTIONS=--max_old_space_size=8096 node --max-old-space-size=8096 app.js",
  4. "limit": "cross-env LIMIT=8096 increase-memory-limit"
  5. },

参考链接:

https://www.cnblogs.com/IwishIcould/p/17019276.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/468655
推荐阅读
相关标签
  

闽ICP备14008679号