zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

Out of memory error

Open timstoop opened this issue 9 years ago • 14 comments

So I got the following stack trace after I had been trading for a little while:

---------------------------- STARTING LIVE TRADING ----------------------------
2017-08-04 08:30:00  191.150 XETH-ZEUR   +0.1%      957   50 +    191.4998186.3962           0.00 XETH  32.06100 ZEUR    +0.0%    0.0%
2017-08-04 08:56:00  190.990 XETH-ZEUR   -0.1%     1042     - 49  191.3438186.3962           0.00 XETH  32.06100 ZEUR     0.0%   +0.1%
2017-08-04 09:22:00  191.000 XETH-ZEUR   +0.0%     1150     - 49  191.3000186.3962           0.00 XETH  32.06100 ZEUR     0.0%   +0.1%
2017-08-04 09:23:38  191.094 XETH-ZEUR   +0.0%       13   50 +    191.0961186.3962           0.00 XETH  32.06100 ZEUR     0.0%   +0.0%
<--- Last few GCs --->

 6946567 ms: Mark-sweep 1342.4 (1418.0) -> 1342.3 (1418.0) MB, 748.7 / 0.2 ms [allocation failure] [GC in old space requested].
 6947303 ms: Mark-sweep 1342.3 (1418.0) -> 1342.3 (1418.0) MB, 736.3 / 0.1 ms [allocation failure] [GC in old space requested].
 6948054 ms: Mark-sweep 1342.3 (1418.0) -> 1342.0 (1418.0) MB, 750.9 / 0.1 ms [last resort gc].
 6948791 ms: Mark-sweep 1342.0 (1418.0) -> 1342.0 (1418.0) MB, 736.9 / 0.1 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0x93fcae3fa99 <JS Object>
    1: request [https.js:~192] [pc=0x1c1eacc8fbdd] (this=0x2acaead35331 <an Object with map 0x240faeac7d39>,options=0x1f3c800bcb79 <an Object with map 0x312744a61849>,cb=0x93fcae04241 <undefined>)
    2: arguments adaptor frame: 1->2
    3: start [/app/node_modules/request/request.js:755] [pc=0x1c1eac91d7d9] (this=0x382d777e71e9 <a Request with map 0x312744a3df61>)
    4: write [/app/node_module...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x109cafc [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::StoreIC::LookupForWrite(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
13: v8::internal::StoreIC::UpdateCaches(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
14: v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::Object::StoreFromKeyed) [node]
15: v8::internal::KeyedStoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [node]
16: v8::internal::Runtime_KeyedStoreIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node]
17: 0x1c1eaba060c7

At this point, it seems zenbot no longer wants to trade this pair, as it keeps stuck on:

fetching pre-roll data:

I'm running the code in Docker containers and another trading bot is running just fine (in another container). Any hints on what's going on here or what I should be doing to clean this up? I'm using the trust_distrust strategy for this bot.

Any help is appreciated!

timstoop avatar Aug 04 '17 10:08 timstoop

What kind of machine are you running this on? Are there any memory limits set on your docker?

DeviaVir avatar Aug 04 '17 10:08 DeviaVir

8 CPU thread (4 cores + HT) and 24GB RAM... would expect it to be enough. However, I do not see RAM usage increase all that much, maybe 1GB or so. I have not manually set any limits on docker and I generally have a lot more and larger containers running. Unless the NodeJS container is 32bit and can only support up to 3.5GB of RAM, I doubt the problem is in my machine. Any place else where I should be looking?

timstoop avatar Aug 04 '17 12:08 timstoop

I got this too a few days back

ghost avatar Aug 04 '17 18:08 ghost

me too, and I don't use docker 2gb ram, node 7

<--- Last few GCs --->

[13769:0x32747f0] 31441514 ms: Mark-sweep 2871.0 (3302.1) -> 2870.9 (3185.6) MB, 14313.8 / 8.5 ms  (+ 0.0 ms in 0 steps since st
art of marking, biggest step 0.0 ms, walltime since start of marking 15828 ms) last resort
[13769:0x32747f0] 31457874 ms: Mark-sweep 2870.9 (3185.6) -> 2870.9 (3175.6) MB, 16271.3 / 7.2 ms  last resort


<--- JS stacktrace --->

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

Security context: 0x33f23b193471 <JS Object>
    2: serialize [.../zenbot/node_modules/bson/lib/bson/bson.js:~47] [pc=0x29a156d41798](this=0x2d2419f1999 <a BSO
N with map 0x25301c410901>,object=0x2f91edfef951 <an Object with map 0x181df46dd39>,options=0x2f91edfeea69 <an Object with map 0
x25301c420601>)
    3: toBin [.../zenbot/node_modules/mongodb-core/lib/connection/commands.js:140] [pc=0x29a15746c69b](this=0x2...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x134e91c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewCode(v8::internal::CodeDesc const&, unsigned int, v8::internal::Handle<v8::internal::Object>, bool
, bool, int, bool) [node]
 6: v8::internal::CodeGenerator::MakeCodeEpilogue(v8::internal::MacroAssembler*, v8::internal::EhFrameWriter*, v8::internal::Com
pilationInfo*, v8::internal::Handle<v8::internal::Object>) [node]
 7: v8::internal::FullCodeGenerator::MakeCode(v8::internal::CompilationInfo*, unsigned long) [node]
 8: v8::internal::FullCodegenCompilationJob::ExecuteJobImpl() [node]
 9: v8::internal::CompilationJob::ExecuteJob() [node]
10: 0xd13b13 [node]
11: 0xd16f1e [node]
12: 0xd195de [node]
13: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) 
[node]
14: v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::internal::Isolate*) [node]
15: 0x29a1563040c7
Aborted (core dumped)

grigio avatar Sep 18 '17 17:09 grigio

same with i5 and 16 GB

<--- Last few GCs --->

[23401:0x2fdfb00] 420607 ms: Mark-sweep 1412.0 (1468.5) -> 1411.8 (1455.5) MB, 1723.5 / 1.5 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 1724 ms) last resort GC in old space requested [23401:0x2fdfb00] 422163 ms: Mark-sweep 1411.8 (1455.5) -> 1411.8 (1455.5) MB, 1555.8 / 1.4 ms last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0x117c43a25ee1 2: serializeInto(aka serializeInto) [/home/matteo/Dropbox/script/trading/zenbot/node_modules/bson/lib/bson/parser/serializer.js:733] [bytecode=0x25b1a0b2ca39 offset=2367](this=0x1e12a8902311 ,buffer=0x25b1a0b07631 ,object=0x35109f957101 ,checkKeys=0x1e12a8902421 ,startingIndex=84,depth=3,serializeFunctions=0x1e12...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [node] 2: 0x121a7ac [node] 3: v8::Utils::ReportOOMFailure(char const*, bool) [node] 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node] 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node] 6: v8::internal::LoadIC::LoadFullChain(v8::internal::Handlev8::internal::Map, v8::internal::Handlev8::internal::Object, v8::internal::Handlev8::internal::Name, v8::internal::Handlev8::internal::Smi) [node] 7: v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [node] 8: v8::internal::LoadIC::Load(v8::internal::Handlev8::internal::Object, v8::internal::Handlev8::internal::Name) [node] 9: v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [node] 10: 0x1e5e54b0463d

luponata avatar Dec 24 '17 15:12 luponata

I also have an I5 and 16 gb ram and i get this. Crashes my computer.

Primea1 avatar Dec 31 '17 05:12 Primea1

Just got this today:

<--- Last few GCs --->

[2705:0x31cddc0] 473222401 ms: Scavenge 1063.5 (1118.0) -> 1062.8 (1118.0) MB, 7.9 / 0.0 ms  allocation failure
[2705:0x31cddc0] 473222412 ms: Scavenge 1063.6 (1118.0) -> 1062.8 (1118.0) MB, 4.7 / 0.0 ms  allocation failure
[2705:0x31cddc0] 473225271 ms: Scavenge 1063.8 (1118.0) -> 1062.9 (1118.0) MB, 121.3 / 37.8 ms  allocation failure
[2705:0x31cddc0] 473228546 ms: Scavenge 1063.8 (1118.0) -> 1063.1 (1118.0) MB, 25.9 / 2.2 ms  allocation failure


<--- JS stacktrace --->

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

Security context: 0x7f788325739 <JSObject>
    1: dataMessage [~/zenbot/node_modules/gdax/node_modules/ws/lib/Receiver.js:~359] [pc=0x37bd05ce4e0e](this=0x1f9786f09f9 <Receiver map = 0x28f62a4b17a1>)
    2: /* anonymous */ [~/zenbot/node_modules/gdax/node_modules/ws/lib/WebSocket.js:~140] [pc=0x37bd05f09b67](this=0x1f9786f0b31 <TLSSocket map = 0x36bd55504461>,data=0x383a073ffb11 <Uint8Array map = 0x75f39536c89>)
    ...

glennfu avatar Jan 25 '18 18:01 glennfu

Same error here. First darwin wouldn't give any good results, showed currency_capital error so I tried running the sim myself. It became very slow minutes before the error was shown, not usual speedy sim whizzing by. This one ground to a halt.

2 things changed from previous generations.

  1. population size decreased from 909 to 303
  2. --start=201801220030 --end=201802140500 became values below

Resulted from the command

zenbot.bat sim gdax.LTC-USD --period_length=241m --min_periods=40 --markdown_buy_pct=-0.9817790501161023 --markup_sell_pct=0.33335068998603434 --order_type=maker --sell_stop_pct=30 --buy_stop_pct=8 --profit_stop_enable_pct=9 --profit_stop_pct=9 --trend_ema=13 --oversold_rsi_periods=19 --oversold_rsi=20 --backtester_generation=1 --strategy=trend_ema --maxCores=2 --start=201712111340 --end=201801160100 --asset_capital=4 --currency_capital=1000 --filename=none

Error message

` <--- Last few GCs --->

[1756:000002080C5C0170] 191100 ms: Mark-sweep 1405.1 (1433.3) -> 1405.1 (1433.3) MB, 1174.2 / 0.0 ms last resort GC in old space requested

<--- JS stacktrace --->

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

Security context: 0000019DD39A5EE1 2: serializeInto(aka serializeInto) [C:\Users\Travis\Documents\Code\zenbot2\node_modules\bson\lib\bson\parser\serializer.js:733] [bytecode=00000268CACE3599 offset=2367](this=00000185EE982311 ,buffer=000000C93EBD7251 ,object=000003CAE7648969 ,checkKeys=00000185EE982421 ,startingIndex=0,depth=0,serializeFunct...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node_module_register 2: v8::internal::FatalProcessOutOfMemory 3: v8::internal::FatalProcessOutOfMemory 4: v8::internal::Factory::NewFixedArray 5: std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate 6: std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate 7: std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate 8: std::vector<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> >::_Reallocate 9: 00000254C25047A1 `

archaistvolts avatar Feb 22 '18 17:02 archaistvolts

Also have this error ... The command runs with normal behaviour for a few data-days (this ingestion take about 10 minutes) and then is slows to a crawl before crashing back to the shell.

Resulted from command:

./zenbot.sh train --start_training 1518587835000 --days_training 10 --start_test 1519538235000 --days_test 4 --period 5m

Starts out as:

Generating training candlesticks from database...
2018-02-14 09:49:56  7140.43 BTC-EUR   +0.00%      244                    
2018-02-14 10:14:57  7175.35 BTC-EUR   -0.04%       99                    
2018-02-14 10:44:55  7154.35 BTC-EUR   +0.01%      363                    
2018-02-14 11:09:55  7157.80 BTC-EUR   +0.33%      317                    
2018-02-14 11:29:57  7162.56 BTC-EUR   -0.04%      303                    
2018-02-14 11:54:59  7199.49 BTC-EUR   +0.00%      416                    
2018-02-14 12:14:59  7484.43 BTC-EUR   +1.96%      728                    

until it starts slowing down to a crawl

2018-02-18 16:49:59  8575.00 BTC-EUR   -0.17%      168                    
2018-02-18 17:04:58  8648.89 BTC-EUR   +0.75%      425                    
2018-02-18 17:09:42  8659.00 BTC-EUR   +0.11%      280                    
2018-02-18 17:14:56  8698.10 BTC-EUR   +0.45%      217                    
2018-02-18 17:19:48  8693.07 BTC-EUR   -0.06%      334                    
2018-02-18 17:29:56  8662.59 BTC-EUR   -0.26%      222                    
2018-02-18 17:34:58  8660.21 BTC-EUR   -0.03%      294                    
2018-02-18 17:39:51  8683.35 BTC-EUR   +0.26%      211  

and it crashes

Error message

<--- Last few GCs --->

[7334:0x3275b20]   477791 ms: Mark-sweep 1383.8 (1447.8) -> 1383.8 (1448.3) MB, 2204.1 / 0.0 ms  allocation failure GC in old space requested
[7334:0x3275b20]   480021 ms: Mark-sweep 1383.8 (1448.3) -> 1383.8 (1412.3) MB, 2230.3 / 0.0 ms  last resort GC in old space requested
[7334:0x3275b20]   482166 ms: Mark-sweep 1383.8 (1412.3) -> 1383.8 (1412.3) MB, 2145.3 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0x5d4d60a5ee1 <JSObject>
    1: updatePeriod [/home/zenbot/zenbot/lib/engine.js:~194] [pc=0x122daec16281](this=0x254605e8beb1 <JSGlobal Object>,trade=0x114b15308f49 <Object map = 0x2dab6294c5a9>)
    2: /* anonymous */(aka /* anonymous */) [/home/zenbot/zenbot/node_modules/async/dist/async.js:~4081] [pc=0x122daead5a2e](this=0x3cf28f202311 <undefined>,items=0x15f52af82241 <JSArray[1]>,cb=0x15f52af824e1 <JSFunction (sfi = ...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x121a2cc [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewUninitializedFixedArray(int) [node]
 6: 0xe1c3b3 [node]
 7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 8: 0x122dae98463d
./zenbot.sh: line 2:  7334 Aborted                 env node zenbot.js $@

JaapSch avatar Mar 01 '18 10:03 JaapSch

Memory workarounds:

  1. Add --keep_lookback_periods=100 to your command. The lookback periods are really only for the GUI. This means that s.lookback.length will never be more than 100 so make sure none of your indicators need more than that, or adjust it higher if needed. The default is 50,000, which is bonkers high and takes a ton of memory.
  2. At the bottom of your conf.js find c.output.api.on = true and change it to c.output.api.on = false. This is only needed if you're running the GUI. If you're not, it's just a memory hog.

glennfu avatar Mar 01 '18 14:03 glennfu

@glennfu 👍 that works like a charm :-) ... Still ... default settings should not crash the bot ... should it now ;-p

JaapSch avatar Mar 02 '18 09:03 JaapSch

So i ran in to this also on a raspberry pi 4. Thinking it was a pice of crap i dusted of a old ibm server with loads of memory. Happily installing Ubuntu thinking to beat that error! Aand i get the same one even if it was running on less than 10% of total memory... So it seems there is a memory limit it runs in to.

Can be fixed easily enough by running zenbot with this command: Node >8.0.0 node -max-old-space-size=4096 zenbot.js "followed by what you want to execute"

Node <8.0.0 it should be: node --max-executable-size=4096 zenbot.js

That will let it use more than the default set limit of memory.

Zenbot seems to be quite happy running on 1.8Gb max memory in general, but you can set it to what you want.

#increase to 2gb node --max-old-space-size=2048 zenbot.js

#increase to 3gb node --max-old-space-size=3072 zenbot.js

#increase to 4gb node --max-old-space-size=4096 zenbot.js

#increase to 5gb node --max-old-space-size=5120 zenbot.js

#increase to 6gb node --max-old-space-size=6144 zenbot.js

#increase to 7gb node --max-old-space-size=7168 zenbot.js

#increase to 8gb node --max-old-space-size=8192 zenbot.js

For global Node memory increase just type: Linux: export NODE_OPTIONS=--max_old_space_size=4096 Windows: (should be something like this)

Open command prompt and type %appdata% press enter
Navigate to %appdata% > npm folder
Open or Edit ng.cmd in your favorite editor
Add --max_old_space_size=8192 to the IF and ELSE block

and so on. Maybe someone will find this useful :)

kimasplund avatar Apr 08 '20 11:04 kimasplund

@DeviaVir Think you can close this bug :)

kimasplund avatar Apr 08 '20 12:04 kimasplund

Might still be useful to document this https://github.com/DeviaVir/zenbot/tree/unstable/docs

DeviaVir avatar Apr 08 '20 13:04 DeviaVir