pilwon / node-ib

Interactive Brokers TWS API client library for Node.js
382 stars 133 forks source link

Process out of Memory #72

Open closelate opened 8 years ago

closelate commented 8 years ago

When I have multiple clients connect to ib server, I have fatal error "process out of memory" it is in the line 84 of controller.js. "this._ib.emit.apply(this._ib, arguments);"
Is there anyway to solve this problem? I can't find where is the memory leak. Thanks The error is as following:

<--- Last few GCs --->

14452083 ms: Mark-sweep 1394.5 (1457.4) -> 1398.1 (1457.4) MB, 2424.1 / 0 ms [al location failure] [GC in old space requested]. 14454442 ms: Mark-sweep 1398.1 (1457.4) -> 1398.1 (1457.4) MB, 2358.6 / 0 ms [al location failure] [GC in old space requested]. 14456756 ms: Mark-sweep 1398.1 (1457.4) -> 1392.2 (1457.4) MB, 2318.7 / 0 ms [la st resort gc]. 14459021 ms: Mark-sweep 1392.2 (1457.4) -> 1394.3 (1457.4) MB, 2259.1 / 0 ms [la st resort gc].

<--- JS stacktrace --->

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

Security context: 000001356F0B4639 1: emit [events.js:~117] [pc=000003297D6EC572](this=000003216CF86369 <an IB with map 000002295660DB01>,type=0000024C696565E9 <String[8]: tickSize) 2: arguments adaptor frame: 4->1 4: emit [D:\nodejs\node_modules\npm_IB??????\IB_nodejs_mtrader\node_modules \lib\controller.js:84] [pc=000003297DC81B73](this=000000DCF770EEA1 <a Controlle r with map 0000004C4A3EEEE1) 5: argument...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

buzzcloudau commented 8 years ago

What are you setting your old-space to?

Try starting node with (adjusted for your needs)

--max-old-space-size=2048

Also, are you making your calls in a loop, or subscribing to the callbacks?

closelate commented 8 years ago

I set --max_old_space_size=64000 and I did not make calls in a loop, all the calls are from client side to POST the JSON file. and in server side, call ib command and handle the callbacks. When more clients calls, it getting very slow and eventually crashed.

buzzcloudau commented 8 years ago

How many clients are you connecting?

closelate commented 8 years ago

3-4 clients

closelate commented 8 years ago

The clients are doing different things, some of them call market data, some of them doing trading. the IB gateway always connected

buzzcloudau commented 8 years ago

--max_old_space_size=64000

Does your machine have 64GB of memory available?

closelate commented 8 years ago

oh, it is 16GB

closelate commented 8 years ago

SO I should set to 16000?

buzzcloudau commented 8 years ago

That is old-space memory. You have to leave enough for the OS, apps, services/servers and regular app memory usage. I would recommend 4098 or less.

closelate commented 8 years ago

OK, I will give it a try, still think there is a memory leak for ib lib.
Thanks!