赞
踩
- <--- Last few GCs --->
-
- [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
-
-
- <--- JS stacktrace --->
-
- FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
- 1: 00007FF7BE2E013F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112495
- 2: 00007FF7BE26F396 DSA_meth_get_flags+65526
- 3: 00007FF7BE27024D node::OnFatalError+301
- 4: 00007FF7BEBA19EE v8::Isolate::ReportExternalAllocationLimitReached+94
- 5: 00007FF7BEB8BECD v8::SharedArrayBuffer::Externalize+781
- 6: 00007FF7BEA2F61C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1468
- 7: 00007FF7BEA2C754 v8::internal::Heap::CollectGarbage+4244
- 8: 00007FF7BEA2A0D0 v8::internal::Heap::AllocateExternalBackingStore+2000
- 9: 00007FF7BEA47D40 v8::internal::FreeListManyCached::Reset+1408
- 10: 00007FF7BEA483F5 v8::internal::Factory::AllocateRaw+37
- 11: 00007FF7BEA5A0EE v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray+46
- 12: 00007FF7BEA5CD4A v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller+74
- 13: 00007FF7BEA5CC6D v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArray+77
- 14: 00007FF7BE9060F3 v8::internal::FeedbackNexus::ic_state+61859
- 15: 00007FF7BE92D867 v8::Message::GetIsolate+83559
- 16: 00007FF7BE92CACF v8::Message::GetIsolate+80079
- 17: 00007FF7BE880F40 v8::internal::JSArray::SetLength+240
- 18: 00007FF7BE8FF629 v8::internal::FeedbackNexus::ic_state+34521
- 19: 00007FF7BE791A85 v8::internal::CompilationCache::IsEnabledScriptAndEval+27701
- 20: 00007FF7BEC2F3E1 v8::internal::SetupIsolateDelegate::SetupHeap+494417
- 21: 000001ED3BDF1521
- // 全局变量
- let total = []
- //内存溢出
- const toolsMemory = async (req, res) => {
- const { uid } = req.body
-
- function getMemory(n = 1) {
- let memory = process.memoryUsage()
- console.log(`rss:${(memory.rss / 1024 / 1024).toFixed(1)}MB`)
- console.log(`external:${(memory.external / 1024 / 1024).toFixed(1)}MB`)
- console.log(
- `arrayBuffers:${(memory.arrayBuffers / 1024 / 1024).toFixed(1)}MB`
- )
- console.log(`申请到内存:${(memory.heapTotal / 1024 / 1024).toFixed(1)}MB`)
- console.log(`已使用内存:${(memory.heapUsed / 1024 / 1024).toFixed(1)}MB`)
-
- let totalmem = os.totalmem() // 以整数形式返回系统内存总量(以字节为单位B)
- let freemem = os.freemem() // 以整数形式返回空闲的系统内存量(以字节为单位B)。
- console.log(
- `系统总内存:${(totalmem / 1024 / 1024).toFixed(1)}\n系统空闲内存:${(
- freemem /
- 1024 /
- 1024
- ).toFixed(1)}`
- )
- console.log(`--------------------循环了${n}次`)
- return `
- rss:${(memory.rss / 1024 / 1024).toFixed(1)}MB
- external:${(memory.external / 1024 / 1024).toFixed(1)}MB
- arrayBuffers:${(memory.arrayBuffers / 1024 / 1024).toFixed(1)}MB
- 申请到内存:${(memory.heapTotal / 1024 / 1024).toFixed(1)}MB
- 已使用内存:${(memory.heapUsed / 1024 / 1024).toFixed(1)}MB
- 系统总内存:${(totalmem / 1024 / 1024).toFixed(1)}\n系统空闲内存:${(
- freemem /
- 1024 /
- 1024
- ).toFixed(1)}
- `
- }
-
- // 每次都会接受一个大数组
- // function useMem() {
- // let size = 20 * 1024 * 1024
- // let arr = new Array(size)
- // return arr
- // }
-
- // for (let j = 0; j < 100; j++) {
- // getMemory(j + 1)
- // total.push(useMem())
- // }
- // console.log('success')
-
- let info = getMemory()
-
- res.send({
- code: 200,
- data: {
- uid,
- info,
- },
- message: '成功',
- })
- }
解决方案:
- "scripts": {
- "dev1": "cross-env PORT=85 NODE_ENV=development NODE_OPTIONS=--max_old_space_size=8096 nodemon --inspect --max_old_space_size=8096 app.js",
- "dev11": "cross-env PORT=85 NODE_OPTIONS=--max_old_space_size=8096 node --max-old-space-size=8096 app.js",
- "limit": "cross-env LIMIT=8096 increase-memory-limit"
- },
参考链接:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。