Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Discuss, post your questions about TWSLink here.

Users who just registered, please write an email to
forum@trade-commander.de
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by Rocket130713 »

Hello, in TradeStation script I called GET_ACC_VAL and GET_POSITIONS TWS-Link functions 50 times in a row (at once) with only 1ms sleep in between each function call and this caused my CPU to run at near 100% all the time as I have 23 scripts all running at once, and this then (for the first time ever) caused my trading laptop to over-heat and shut down which in turn corrupted my hard drive data. Do you think that rather using 1ms sleep ie: WAITDLL(1) is not enough sleep? should I try 5ms or 10 ms i.e. WAITDLL(10)? would this makes much difference to CPU usage in your opinion? have you seen this problem before? Many thanks in advance. Kind regards, Rod.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by board_admin »

Sorry, i can't believe TWSLink causes corrupted harddrives. Please find another cause for this and allow me a comment:
Running a trading machine on a laptop is a bit careless.

Generally TWSLink spreads work into threads. Having multiple cores is an advantage, memory as well.
If you have a millisecond delay between each causes it is unlikely to get 100 % CPU load by TWSLink host process.

If you run TWSLink, you most likely also run a host process and TWS and some other application. Make sure you
have sufficient memory to have all application open with some reserve.

If you have logfiles with records about this situation, you could attach them. Will have a look on this.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by board_admin »

Just made a test. Calling 100 times GET_ACC_VAL took 78 milliseconds on my virtual machine (6 cores, 16 GB) .
There is absolutely no bottleneck and no need to call a wait function between function calls.

You can check this also when loading the script "account- and portfolio data" in the batchtester.
Set 300 as number for loops. Open taskmanager to watch CPU load during run. In my case
it does not exceed 45 %.

Can you give some information about your laptop. Cores, memory, frequency. Do you have sufficient free hdd space ?
If you have not sufficient memory, the system is forced to swap memory to hdd and if you not have sufficient free hdd
space, you get a problem.

However, GET_ACC_VAL is not notable raising memory usage because It makes a simple database query loading some KB into memory
which are unloaded after call.

Very unlikely TWSLink was the cause for this machine lock.

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by Rocket130713 »

Hello, I was able to isolate the problem which caused TradeStation to lock-up and PC overheat and shut-down. It was due to using a 999ms sleep in between calling GET_POSITION function 50 times in a row, if I remove the WAITDLL(999); lines in between function calls TradeStation does not lock up and everything is fine. Very strange. Don't understand why, but it does not matter, since I have removed all WAITDLL functions from my code and now everything works fine. Hopefully this info can help someone else who may have a similar problem. Overall, I'm extremely happy with TWS-Link software, it does a great job. Many thanks in advance. Kind regards, Rod.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by board_admin »

WAITDLL makes a stop of the calling thread for the specified time. The thread is going into idle state. No CPU load.
It can cause a TradeStation lock (freeze) for the time of sleep, presumed it is called in all threads, but for sure not a machine lock.

WAITDLL does nothing else than calling a Windows API function Sleep.

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by Rocket130713 »

Hello, what you said in your previous post makes sense. In my tests when I call WAITDLL(1) in between calling Get_Acc_Val function (50 times in a row i.e. sub-account 1-50) TS locks up only "a little bit", but if I use WAITDLL (999) in between calling functions TS locks up "completely". You are right in that the PC machine does not lock up at all and that the CPU usage is not affected by the WAITDLL(999) function, the "only" problem is that TS locks-up depending on how large the WAITDLL(x) ms time is. It's not a big deal as I don't need to use the WAITDLL functions anyhow. Still really happy with TWS-Link. Thanks for your help and reply. Kind regards, Rod.

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by Rocket130713 »

Hello, just in case I can help someone else, I thought I should report my final testing results and "past" problems re TWS-Link. I found that calling WAITDLL(5) many times in the TS script and trading with many scripts (trading 23 markets/charts) causes TS to lock-up/freeze/become non-responsive. Also found that if we set the TWS log level to "Elevated" (which is default) then this causes the CPU usage to increase from 3% average (range 1% to 8%) to 15% average (range 3% to 22%) as this causes TWS to write heaps of data to the TWS log file and hard drive which uses up heaps of CPU resources. Still don't know why my laptop overheated and shut down but it is probably a result of both of the above combined and also looping the TS script too many times per second when the markets are busy. Now that all problems have been fixed and my CPU usage ranges from 1% - 8% with an average of only 3% I'm extremely happy with TWS-Link. Thanks to the TWS-Link developer for such great software, and for all of his help on this forum. Kind regards, Rod.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by board_admin »

Thank you for update.

Just for clarification. A WAITDLL call puts a thread into an idle state. It locks the calling thread for this time.
It is the opposite of what could "overheat" an CPU.

A high loglevel can raise CPU load. In particular loglevel 0. Because this means full logging and also
it produces much megabytes of data. This is boosted at busy times and you subscribed to market data.
(Leaving loglevel at 0 is careless).

Normally, loglevel 2 or 3 should be ok (higher loglevel ,means less logging). If you have a problem and like to track it, set it to 1.

TWSLink logs CPU time imposed by the entire host process (so TWSLink + all other components in this process)
at the end of the logfile on shutdown.

It would be a useful information what your hardware is, CPU cores, frequency, RAM and free HD
and what else is running on your machine.

TWSLink is designed for a multithread environment and for low latency function calls.
When ever a buffer is useful and is not taking too much memory, a data is buffered to reduce
time of access.

Please keep in mind that functions like REGISTER_CONTRACT and CONNECT need to be called only once.
(i say this, because i already saw a REGISTER_CONTRACT before each PLACE_ORDER in a customers logfile).

Rocket130713
Posts: 21
Joined: Sat Mar 03, 2018 9:23 am

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by Rocket130713 »

Hello, thank you for you reply and advice. I want to set the log level to number 4 (which is log level "low"), how do I do this so that every time TWS_Link is launched (loaded) the log level remains "fixed" on number 4/low? Is there a place in an XML file (if so, what is the name of this XML file?) where I can change the log level to number 4 permanently? Many thanks in advance. Kind regards, Rod.

board_admin
Site Admin
Posts: 244
Joined: Mon Apr 24, 2017 3:24 pm

Re: Calling Get_Acc_Val & Get_Postions functions 50 times in a row caused my PC to overheat and shut down

Post by board_admin »

You find the settings file in the x86 programs folder on x64 machines or in the programs folder on x86 machines:

Code: Select all

C:\Program Files (x86)\trade-commander\twslink2\xml\twslink.xml
Open the xml in an editor and search the line below and set the loglevel 4 behind the "v".

Code: Select all

<dllll ttl="DLL Loglevel" v="4" keepopen="0" exceptdump="0" dumpexclusive="0" bypasslic="0" perflog="0" folder="" zipold="0" processid="0" acclog="4" create_host_folder="0"/>

Post Reply