不和谐机器人的Heroku内存错误(Node.js)

时间:2020-10-03 17:40:17

标签: node.js heroku

由于某种原因,我偶尔会不断收到此错误,而且我不知道如何解决。内存一直在说它已超出限制,这导致我的机器人不得不在我不希望的地方重新启动。这会导致机器人中的当前代码出现问题,而我不知道如何解决这些问题。有什么想法吗?

谢谢!

2020-10-03T17:13:14.381800+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381830+00:00 app[Worker.1]: <--- Last few GCs --->
2020-10-03T17:13:14.381831+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381835+00:00 app[Worker.1]: [4:0x3d6e300] 10517035 ms: Mark-sweep 251.8 (257.5) -> 251.8 (257.5) MB, 654.6 / 0.0 ms  (average mu = 0.193, current mu = 0.058) allocation failure GC in old space requested
2020-10-03T17:13:14.381835+00:00 app[Worker.1]: [4:0x3d6e300] 10517658 ms: Mark-sweep 251.8 (257.5) -> 251.7 (257.5) MB, 569.5 / 0.0 ms  (average mu = 0.145, current mu = 0.084) allocation failure GC in old space requested
2020-10-03T17:13:14.381836+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381836+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381837+00:00 app[Worker.1]: <--- JS stacktrace --->
2020-10-03T17:13:14.381837+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381838+00:00 app[Worker.1]: ==== JS stack trace =========================================
2020-10-03T17:13:14.381838+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381839+00:00 app[Worker.1]:     0: ExitFrame [pc: 0x13cf099]
2020-10-03T17:13:14.381840+00:00 app[Worker.1]:     1: StubFrame [pc: 0x142b232]
2020-10-03T17:13:14.381840+00:00 app[Worker.1]: Security context: 0x3f8bca2008d1 <JSObject>
2020-10-03T17:13:14.381841+00:00 app[Worker.1]:     2: nextTick [0xb3f0cf95c01] [internal/process/task_queues.js:129] [bytecode=0x60fb2779c41 offset=319](this=0x2fa425bbfb09 <process map = 0x3912d8e02559>,0x0414e95ed279 <JSFunction onSocketNT (sfi = 0x10e0661aebe1)>)
2020-10-03T17:13:14.381842+00:00 app[Worker.1]:     3: arguments adaptor frame: 3->1
2020-10-03T17:13:14.381842+00:00 app[Worker.1]:     4: onSocket [0x10e0661b9ca9] [_http_client.js:732] [bytecode=0x60fb2774...
2020-10-03T17:13:14.381843+00:00 app[Worker.1]: 
2020-10-03T17:13:14.381843+00:00 app[Worker.1]: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
2020-10-03T17:13:14.423372+00:00 app[Worker.1]:  1: 0xa093f0 node::Abort() [node]
2020-10-03T17:13:14.426419+00:00 app[Worker.1]:  2: 0xa097fc node::OnFatalError(char const*, char const*) [node]
2020-10-03T17:13:14.427061+00:00 app[Worker.1]:  3: 0xb8431e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
2020-10-03T17:13:14.427693+00:00 app[Worker.1]:  4: 0xb84699 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
2020-10-03T17:13:14.428406+00:00 app[Worker.1]:  5: 0xd31055  [node]
2020-10-03T17:13:14.429136+00:00 app[Worker.1]:  6: 0xd316e6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
2020-10-03T17:13:14.437880+00:00 app[Worker.1]:  7: 0xd3df65 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
2020-10-03T17:13:14.441802+00:00 app[Worker.1]:  8: 0xd3ee15 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2020-10-03T17:13:14.445799+00:00 app[Worker.1]:  9: 0xd418cc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2020-10-03T17:13:14.447204+00:00 app[Worker.1]: 10: 0xd0df81 v8::internal::Factory::NewTransitionArray(int, int) [node]
2020-10-03T17:13:14.447945+00:00 app[Worker.1]: 11: 0xf56bb7 v8::internal::TransitionsAccessor::Insert(v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Map>, v8::internal::SimpleTransitionFlag) [node]
2020-10-03T17:13:14.448645+00:00 app[Worker.1]: 12: 0xf036ca v8::internal::Map::ConnectTransition(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::SimpleTransitionFlag) [node]
2020-10-03T17:13:14.457851+00:00 app[Worker.1]: 13: 0xf05d4e v8::internal::Map::CopyReplaceDescriptors(v8::internal::Isolate*, 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]
2020-10-03T17:13:14.458563+00:00 app[Worker.1]: 14: 0xf0635a v8::internal::Map::CopyAddDescriptor(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Descriptor*, v8::internal::TransitionFlag) [node]
2020-10-03T17:13:14.459277+00:00 app[Worker.1]: 15: 0xf06599 v8::internal::Map::CopyWithField(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::FieldType>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::Representation, v8::internal::TransitionFlag) [node]
2020-10-03T17:13:14.459963+00:00 app[Worker.1]: 16: 0xf07d82 v8::internal::Map::TransitionToDataProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::PropertyConstness, v8::internal::StoreOrigin) [node]
2020-10-03T17:13:14.460645+00:00 app[Worker.1]: 17: 0xef841f v8::internal::LookupIterator::PrepareTransitionToDataProperty(v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::StoreOrigin) [node]
2020-10-03T17:13:14.461317+00:00 app[Worker.1]: 18: 0xf2bb66 v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin) [node]
2020-10-03T17:13:14.470104+00:00 app[Worker.1]: 19: 0xed7010 v8::internal::JSObject::DefineOwnPropertyIgnoreAttributes(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::JSObject::AccessorInfoHandling) [node]
2020-10-03T17:13:14.470851+00:00 app[Worker.1]: 20: 0x1062ee8 v8::internal::Runtime_DefineDataPropertyInLiteral(int, unsigned long*, v8::internal::Isolate*) [node]
2020-10-03T17:13:14.471641+00:00 app[Worker.1]: 21: 0x13cf099  [node]
2020-10-03T17:13:14.614446+00:00 heroku[Worker.1]: Process exited with status 134

1 个答案:

答案 0 :(得分:0)

使用Heroku免费层,您最多可以使用512MB。

要做的第一件事是在本地检查您的应用程序正在使用多少内存,然后进行性能分析/改进。使用NodeJS时,可以使用多种资源,其中一个有趣的博客是Understanding memory leaks in Node.js appsHeroku NodeJS Memory use

要考虑的一个因素是Heroku的内存使用情况可能与您的本地实例不同,我遇到了这个问题,经过一些调整后,我无法再减少内存占用量(在我的情况下,我将应用程序移到了另一个云中提供商并解决了问题)。