分配失败-loopback.js中的javascript堆内存不足

时间:2018-12-04 07:37:28

标签: javascript node.js npm loopbackjs

我正在尝试通过loopback.js获取大数据,但出现错误致命错误:CALL_AND_RETRY_LAST分配失败-JavaScript堆内存不足

<--- Last few GCs --->



45903 ms: Mark-sweep 1385.6 (1438.9) -> 1385.6 (1438.9) MB, 742.8 / 0.0 ms (+ 0.8 ms in 1 steps since start of marking, biggest step 0.8 ms) [allocation failure] [GC in old space requested].
   46512 ms: Mark-sweep 1385.6 (1438.9) -> 1387.3 (1422.9) MB, 607.4 / 0.0 ms (+ 0.8 ms in 1 steps since start of marking, biggest step 0.8 ms) [last resort gc].
   47111 ms: Mark-sweep 1387.3 (1422.9) -> 1389.5 (1422.9) MB, 599.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1c6b6bcfb51 <JS Object>
    1: deserializeObject(aka deserializeObject) [/home/ubuntu/veerendergoudapi/node_modules/bson/lib/bson/parser/deserializer.js:~41] [pc=0x1a9fab83915a] (this=0x1c6b6b04381 <undefined>,buffer=0x193d54f18579 <an Uint8Array with map 0xd4eba2066c9>,index=0,options=0x1e11b6cedfc9 <an Object with map 0x19eb230b3809>,isArray=0x1c6b6b04381 <undefined>)
    2: deserialize(aka deserialize) [/home/ubuntu...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x10a3b3c [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewTransitionArray(int) [node]
 6: v8::internal::TransitionArray::Insert(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
 7: v8::internal::Map::CopyReplaceDescriptors(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::DescriptorArray>, v8::internal::Handle<v8::internal::LayoutDescriptor>, v8::internal::TransitionFlag, v8::internal::MaybeHandle<v8::internal::Name>, char const*, v8::internal::SimpleTransitionFlag) [node]
 8: v8::internal::Map::CopyAddDescriptor(v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
 9: v8::internal::Map::CopyWithField(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::Representation, v8::internal::TransitionFlag) [node]
10: v8::internal::Map::TransitionToDataProperty(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
11: v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::StoreFromKeyed) [node]
12: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::Runtime::SetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode) [node]
15: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16: 0x1a9faac092a7
error: Forever detected script was killed by signal: SIGABRT
error: Script restart attempt #571

1 个答案:

答案 0 :(得分:0)

几天前,当我们的应用程序投入生产时,我们面临着类似的问题,大约有200位活跃用户。因此,整个应用程序崩溃了。经过数小时的调试,我们发现其中一个API没有将正确的错误对象传递给回送远程方法回调。

Loopback希望错误对象的格式为[format] [1]

{status:<some statuscode>, message:<error message>, name:<name for the error>}

,我们将实际的异常传递给它,一切都变得一团糟。推送此修复程序后,泄漏和错误消失了。

请确保您已正确处理所有错误对象。

如果正确处理了错误,则获取大型数据集可能会导致堆溢出。请尝试增加它。

node --max-old-space-size=4096 file.js