[MT4] High CPU Usage Issue with MetaTrader 4 on Wine - Seeking Solutions

 
Hello Forum Members,

I'm currently facing a perplexing issue and I'm in search of both answers and potential solutions. I have the MetaTrader 4 application running on my Windows machine, which is equipped with a 4-core CPU. This setup includes a custom expert advisor that operates on all charts (currently 22) simultaneously. On my Windows machine, the CPU utilization never exceeds 20%.

However, when I try to run the same setup on the latest Wine environment, something strange occurs. Wine generates 23-24 tasks to process all the charts, causing the CPU to run at full capacity, with a load average of 22-23. It's important to note that MetaTrader 4 doesn't hang in this scenario, but the high CPU load is a noticeable contrast to the Windows experience.

While I comprehend that the expert advisor is concurrently managing all the charts, I'm determined to find a plausible explanation or solution for Wine's behaviour in creating so many tasks. Any assistance or insights you can provide would be immensely appreciated.

Thank you in advance for your support!
 
You are new and learning MT4 (MQL4) but MT4 will end sooner or later. So it might be better for you to learn MT5 (MQL5) right from the start.
MT4 End Of Life - End of active support for MT4 with no active support and updates; "What the future holds formt4 and the vast array of
MT4 End Of Life - End of active support for MT4 with no active support and updates; "What the future holds formt4 and the vast array of
  • 2023.09.19
  • www.mql5.com
I have heard reports that mt4 is soon to become 'end of life' with no active support or updates. Can anyone explain what the future holds for mt4 and the vast array of millions of ex4 indicators, scripts and ea's. Com/ru/forum/447913/page6#comment_47273082
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
lambdax:
Hello Forum Members,

I'm currently facing a perplexing issue and I'm in search of both answers and potential solutions. I have the MetaTrader 4 application running on my Windows machine, which is equipped with a 4-core CPU. This setup includes a custom expert advisor that operates on all charts (currently 22) simultaneously. On my Windows machine, the CPU utilization never exceeds 20%.

However, when I try to run the same setup on the latest Wine environment, something strange occurs. Wine generates 23-24 tasks to process all the charts, causing the CPU to run at full capacity, with a load average of 22-23. It's important to note that MetaTrader 4 doesn't hang in this scenario, but the high CPU load is a noticeable contrast to the Windows experience.

While I comprehend that the expert advisor is concurrently managing all the charts, I'm determined to find a plausible explanation or solution for Wine's behaviour in creating so many tasks. Any assistance or insights you can provide would be immensely appreciated.

Thank you in advance for your support!

Apples and oranges... UNIX-based operating systems (MacOS, Linux, BSD, etc.) can report on CPU load which is merely the length of the wait-queue of tasks waiting to get some time on the CPU. This can not be compared to the CPU utilization as reported by Windows. If all tasks request to be serviced at the same time but complete their work in a millisecond, you can have a load of 100 with a utilization of only 1%

For Linux webservers that run thousands of tasks in parallel the rule of thumb is that the CPU load should not exceed the amount of cores in the system (usually 48 or higher for professional servers) to have a quick response / low latency. On your 4-core CPU all tasks can run at full speed if the load does not exceed 4. If the load is higher, like you indicate, that means some tasks need to wait a few milliseconds before being serviced by the CPU. As long as your system still feels responsive, this is not a problem.

In my experience, experts/indicators that use OnTimer() in MT5 can cause this in Linux (probably because the tasks all want to be serviced at the same time like the example I gave above). This is not a problem because the timer events will not "stack up". If there is still an unprocessed timer event in the queue, the system will not queue additional timer events.

 
lambdax:
Hello Forum Members,

I'm currently facing a perplexing issue and I'm in search of both answers and potential solutions. I have the MetaTrader 4 application running on my Windows machine, which is equipped with a 4-core CPU. This setup includes a custom expert advisor that operates on all charts (currently 22) simultaneously. On my Windows machine, the CPU utilization never exceeds 20%.

However, when I try to run the same setup on the latest Wine environment, something strange occurs. Wine generates 23-24 tasks to process all the charts, causing the CPU to run at full capacity, with a load average of 22-23. It's important to note that MetaTrader 4 doesn't hang in this scenario, but the high CPU load is a noticeable contrast to the Windows experience.

While I comprehend that the expert advisor is concurrently managing all the charts, I'm determined to find a plausible explanation or solution for Wine's behaviour in creating so many tasks. Any assistance or insights you can provide would be immensely appreciated.

Thank you in advance for your support!

MT4 is single-threaded so one instance can run only on one core. What I would do is split the installation into 2 - i.e. clone the MT4 install and run 11 EA on each instance and see if it helps. I can't guarantee a result, but it's a simple experiment worth trying imo.

 
Marcin Madrzak #:

MT4 is single-threaded so one instance can run only on one core. What I would do is split the installation into 2 - i.e. clone the MT4 install and run 11 EA on each instance and see if it helps. I can't guarantee a result, but it's a simple experiment worth trying imo.

Hi Marcin,

Thanks for your response. Splitting the EA to run into 2 instances yield the same result. The load average end up to be exactly the same as running all 22 at once.

Marcin Madrzak
Marcin Madrzak
  • 2023.09.13
  • www.mql5.com
Trader's profile
 
yoriz #:

Apples and oranges... UNIX-based operating systems (MacOS, Linux, BSD, etc.) can report on CPU load which is merely the length of the wait-queue of tasks waiting to get some time on the CPU. This can not be compared to the CPU utilization as reported by Windows. If all tasks request to be serviced at the same time but complete their work in a millisecond, you can have a load of 100 with a utilization of only 1%

For Linux webservers that run thousands of tasks in parallel the rule of thumb is that the CPU load should not exceed the amount of cores in the system (usually 48 or higher for professional servers) to have a quick response / low latency. On your 4-core CPU all tasks can run at full speed if the load does not exceed 4. If the load is higher, like you indicate, that means some tasks need to wait a few milliseconds before being serviced by the CPU. As long as your system still feels responsive, this is not a problem.

In my experience, experts/indicators that use OnTimer() in MT5 can cause this in Linux (probably because the tasks all want to be serviced at the same time like the example I gave above). This is not a problem because the timer events will not "stack up". If there is still an unprocessed timer event in the queue, the system will not queue additional timer events.

Hi Yoriz, Thank you for the in-depth explanation. I have a 40-core CPU, and my goal is to run approximately 8-9 instances of MT4, each with a 4-core allocation. However, regardless of how high-end the CPU or the allocated resources are, when I run MT4 within a Docker container with Wine, I consistently encounter the same performance issues.
If I were to run 8 containers simultaneously, I suppose the load average would exceed 100. As per your previous response, this load average should be acceptable as long as MT4 remains responsive and capable of executing trades.
To potentially lower the load average and improve performance, do you believe it would be beneficial to update the expert advisors or indicators used in MT4?
Thanks again for your insights.