OnTimer() has a very large delay. How to solve it? - page 4

 
Longsen Chen #:

I made a clean environment. I started only one EA(Timer.EX4) in MT4, which is compiled from the codes as attached.

But I had a log shows 6 seconds delay. This really puzzled me.


Please post your configuration (https://www.mql5.com/en/forum/449342)

What was running on this computer while running this test ? Only one MT4 with this EA ?

How to report technical issues?
How to report technical issues?
  • 2023.06.20
  • www.mql5.com
To get good and efficient help you need to provide all the relevant technical informations about your context when using the application (MT5 deskt...
 
Alain Verleyen #:

Please post your configuration (https://www.mql5.com/en/forum/449342)

What was running on this computer while running this test ? Only one MT4 with this EA ?

Thank you very much for your instructions. I will make another test with the same EA and post the whole report next week.

 

I have made two tests on two computers. Here are reports

Computer 1, Only one MT4 is loaded with no any other application. Only one EA (timer.ex4) is loaded.

#property version   "1.0"
#property copyright "Copyright 2022, Ksana Trading Corp."
#property link      "https://www.ksanatrading.com"

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   if(!EventSetTimer(1))
      return (INIT_FAILED);
   string msg;
   msg = "Monitoring timer delay...";
   Comment(msg);
   Print(msg);
//--- succeed
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();   
}
//+------------------------------------------------------------------+

void OnTimer()
{
   static datetime last_call=0;
   static int gap_max=0;
   datetime now = TimeLocal();
   if(last_call != now)
   {
      if(last_call>0)
      {
         int gap = (int)(now-last_call);
         if(gap>gap_max)
         {
            gap_max=gap;
            string msg;
            msg = StringFormat("Max Delay=%d (s), at %s",gap_max,
               TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS));
            Comment(msg);
            Print(msg);
         }
      }
      last_call = now;
   }
}

Journal log:

2023.07.31 10:01:56.052 Expert Timer USDJPY,M5: loaded successfully

2023.07.31 10:01:44.380 MQL5.chats: activated for 'gchen2101'

2023.07.31 10:01:44.333 MQL5.community: activated for 'gchen2101', balance: 139.86 (frozen: 125.00)

2023.07.31 10:01:43.943 '1818857': previous successful authorization performed from 138.113.221.110

2023.07.31 10:01:43.333 '1818857': login datacenter on DooPrime-Live 4 through Data Center 01 (ping: 5.07 ms)

2023.07.31 10:01:42.427 '1818857': login on DooPrime-Live 4 through Data Center 01 (ping: 5.07 ms)

2023.07.31 10:01:39.896 Data Folder: C:\Users\Administrator\Desktop\Work\MT4\MT4.2

2023.07.31 10:01:39.896 Windows Server 2016 Datacenter x64, IE 11, RDP, UAC, 1 x Intel Core Processor (Broadwell, no TSX), Memory: 300 / 1023 Mb, Disk: 22 / 39 Gb, GMT+8

2023.07.31 10:01:39.896 Doo Prime MT4 Terminal build 1382 started (Doo Prime Limited)


Experts log:

2023.07.31 10:02:52.005 Timer USDJPY,M5: Max Delay=2 (s), at 2023.07.31 10:02:52

2023.07.31 10:02:05.630 Timer USDJPY,M5: Max Delay=1 (s), at 2023.07.31 10:02:05

2023.07.31 10:02:03.599 Timer USDJPY,M5: initialized

2023.07.31 10:02:03.599 Timer USDJPY,M5: Monitoring timer delay...

2023.07.31 10:01:56.052 Expert Timer USDJPY,M5: loaded successfully



 

Computer 2, Only One EA (timer.ex4) is loaded in MT4, there are other terminals (8 MT4 and 2 MT5 ) running on the same computer.

Journal log:

2023.07.31 10:06:59.581 '1900082876': ping to current access point DC_Vir_L19 is 7.28 ms

2023.07.31 10:06:17.657 MQL5.chats: activated for 'gchen2101'

2023.07.31 10:06:17.595 MQL5.community: activated for 'gchen2101', balance: 139.86 (frozen: 125.00)

2023.07.31 10:06:17.204 '1900082876': previous successful authorization performed from 152.32.151.198

2023.07.31 10:06:16.782 '1900082876': login datacenter on ICMarketsSC-Live19 through DC_Vir_L19 (ping: 7.30 ms)

2023.07.31 10:06:16.392 '1900082876': login on ICMarketsSC-Live19 through DC_Vir_L19 (ping: 7.30 ms)

2023.07.31 10:06:14.314 Expert Timer USDJPY,H1: loaded successfully

2023.07.31 10:06:07.407 Data Folder: C:\Users\Administrator\Desktop\Work\MT4\MT4.8

2023.07.31 10:06:07.407 Windows Server 2016 Datacenter x64, IE 11, RDP, UAC, 4 x Common KVM processor, Memory: 5798 / 8191 Mb, Disk: 11 / 39 Gb, GMT+8

2023.07.31 10:06:07.407 Doo Prime MT4 Terminal build 1382 started (Doo Prime Limited)


Experts log:

2023.07.31 10:40:39.992 Timer USDJPY,H1: Max Delay=6 (s), at 2023.07.31 10:40:39

2023.07.31 10:10:43.298 Timer USDJPY,H1: Max Delay=5 (s), at 2023.07.31 10:10:43

2023.07.31 10:08:34.095 Timer USDJPY,H1: Max Delay=3 (s), at 2023.07.31 10:08:34

2023.07.31 10:07:12.360 Timer USDJPY,H1: Max Delay=2 (s), at 2023.07.31 10:07:12

2023.07.31 10:06:19.814 Timer USDJPY,H1: Max Delay=1 (s), at 2023.07.31 10:06:19

2023.07.31 10:06:17.454 Timer USDJPY,H1: initialized

2023.07.31 10:06:17.454 Timer USDJPY,H1: Monitoring timer delay...

2023.07.31 10:06:14.314 Expert Timer USDJPY,H1: loaded successfully


 

Based on the two reports showed above, May I conclude that

1. OnTimer() is affected by other terminals running on the same computer

2. Even in a clean environment (one terminal, one EA), there may have 2 seconds delay for 1 second Timer.

 
Longsen Chen #:

Based on the two reports showed above, May I conclude that

1. OnTimer() is affected by other terminals running on the same computer

2. Even in a clean environment (one terminal, one EA), there may have 2 seconds delay for 1 second Timer.

seems like it.

May I suggest to use TickCount() as it is in milliseconds, instead of using seconds as resolution to measure the drift of timer.

It would also be interesting to see the average call frequency, as well as min and max values.

Also, what are the results from MT5 in comparison?

EDIT: as I mentioned before, it is a preemptive multitasking environment. There is no such thing as a guarantee to when your process/program/thread receives execution time.

This will lead to all kinds of "problems" when dealing with time critical applications. If the load on your "job Queue" is to high, the OS scheduler will not be able to assign a CPU core to your thread in time. This is always the case on preemptive systems.

There is no technical solution to it.
 
fxsaber #:

Try this.

2023.07.31 07:54:53.262 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 2048254 Amount = 129663 
2023.07.29 23:35:13.018 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1525744 Amount = 14026 
2023.07.29 20:22:14.219 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1065637 Amount = 2529 
2023.07.29 20:07:14.747 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1059613 Amount = 1636 
2023.07.29 20:06:08.243 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1031202 Amount = 1570 
2023.07.29 19:52:02.225 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1030533 Amount = 730 
2023.07.29 19:48:27.725 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1029918 Amount = 517 
2023.07.29 19:43:22.662 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1029184 Amount = 214 
2023.07.29 19:42:52.395 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1028800 Amount = 184 
2023.07.29 19:41:25.863 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1028025 Amount = 98 
2023.07.29 19:40:06.473 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1027500 Amount = 19 
2023.07.29 19:39:56.376 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1026009 Amount = 9 
2023.07.29 19:39:50.361 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 1023333 Amount = 3 
2023.07.29 19:39:49.338 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 997213 Amount = 2 
2023.07.29 19:39:48.341 Test9 GBPSGD.rann,M1: Alert: MaxInterval=NewTime-PrevTime = 0 Amount = 1 
2023.07.29 19:39:47.345 Test9 GBPSGD.rann,M1: initialized

The line, where more than two seconds, was formed when I pressed F4 with the MetaEditor closed.


PS WinServer2019 with 10 MT5 and 3 MT4 - without the problem.

 

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

MT5 и скорость в боевом исполнении

fxsaber, 2020.11.10 08:41

Virtual with 0.6 ms ping (< 1 ms). Order/position modifications last from several tens to thousands of milliseconds. Server logs show values < 1 ms.

LatencyMon showed such horror.

Check your remote machines. Zero ping means nothing. It may turn out that it is more profitable to trade from a home machine.


Threat How to check VPS from MQ - not at all clear.

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Ошибки, баги, вопросы

Renat Fatkhullin, 2020.07.31 19:06

Here I have on a regular Intel Core i7-7820HQ @ 2.90GHz:


Good utility, I will test our servers.

Only after testing it is necessary to remove the program, as it installs the driver.
 
Dominik Christian Egert #:
seems like it.

May I suggest to use TickCount() as it is in milliseconds, instead of using seconds as resolution to measure the drift of timer.

It would also be interesting to see the average call frequency, as well as min and max values.

Also, what are the results from MT5 in comparison?

EDIT: as I mentioned before, it is a preemptive multitasking environment. There is no such thing as a guarantee to when your process/program/thread receives execution time.

This will lead to all kinds of "problems" when dealing with time critical applications. If the load on your "job Queue" is to high, the OS scheduler will not be able to assign a CPU core to your thread in time. This is always the case on preemptive systems.

There is no technical solution to it.

Yes. I can use TickCount() to replace TimeLocal() so we can get the delay in millisecond.

When we have delay in millisecond, we can get minimum interval to see if sometimes the scheduler executes sooner.

I can do the same test for MT5, in the same environment as a comparison.

Maybe at the end of this investigation, we have no solution as Windows is a preemptive system. But we can consider Linux.

 
fxsaber #:

Hi Fxsaber, Are you introducing an application to test windows system environment?

It's a good idea to understand the hardware and software environment.

Reason: